#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*/ perror(char *);
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");
    perror("    ");
  } 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     1173 <hpet_open_close+0x33>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11c8 <hpet_open_close+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bb <hpet_open_close+0x7b>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
jmp    11c3 <hpet_open_close+0x83>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    11c8 <hpet_open_close+0x88>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpet_open_close>:
push   %rax
cmp    $0x1,%edi
jne    1163 <hpet_open_close+0x23>
mov    (%rsi),%rdi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1179 <hpet_open_close+0x39>
mov    %eax,%edi
pop    %rax
jmp    1030 <close@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
pop    %rax
jmp    1040 <fprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xea7(%rip),%rdi
pop    %rax
jmp    1060 <perror@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"
@.str.2 = [5 x i8] c" \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 %27
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 %23
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))
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %11
%24 = load i32, i32* %5
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26, %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"
@.str.2 = [5 x i8] c" \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 %18
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 %16
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))
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %7
%17 = tail call i32 @close(i32 %10)
br label %18
18: ; preds = %12, %16, %4
ret void
}