#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void hpet_open_close(int argc, const char **argv) {
  int fd;
  if (argc != 1) {
    fprintf(stderr, "hpet_open_close: device-name\n");
    return;
  }
  fd = open(argv[0], O_RDONLY);
  if (fd < 0)
    fprintf(stderr, "hpet_open_close: open failed\n");
  else
    close(fd);
  return;
}


x86 assembly (clang, -O0):
<hpet_open_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
je     1163 <hpet_open_close+0x33>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11ac <hpet_open_close+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119f <hpet_open_close+0x6f>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11a7 <hpet_open_close+0x77>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    11ac <hpet_open_close+0x7c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpet_open_close>:
push   %rax
cmp    $0x1,%edi
jne    1153 <hpet_open_close+0x23>
mov    (%rsi),%rdi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1169 <hpet_open_close+0x39>
mov    %eax,%edi
pop    %rax
jmp    1030 <close@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
pop    %rax
jmp    1040 <fprintf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
pop    %rax
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"hpet_open_close: device-name\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_open_close: open failed\0A\00"
define void @hpet_open_close(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %26
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %25
22: ; preds = %11
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25, %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"hpet_open_close: device-name\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_open_close: open failed\0A\00"
define void @hpet_open_close(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %17
15: ; preds = %7
%16 = tail call i32 @close(i32 %10)
br label %17
17: ; preds = %12, %15, %4
ret void
}