#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 */
struct hpet_info {
  int hi_ireqfreq;
  int hi_flags;
  int hi_hpet;
  int hi_timer;
};

/* Variables and functions */
int /*<<< orphan*/ HPET_INFO;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct hpet_info *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void hpet_info(int argc, const char **argv) {
  struct hpet_info info;
  int fd;
  if (argc != 1) {
    fprintf(stderr, "hpet_info: device-name\n");
    return;
  }
  fd = open(argv[0], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "hpet_info: open of %s failed\n", argv[0]);
    return;
  }
  if (ioctl(fd, HPET_INFO, &info) < 0) {
    fprintf(stderr, "hpet_info: failed to get info\n");
    goto out;
  }
  fprintf(stderr, "hpet_info: hi_irqfreq 0x%lx hi_flags 0x%lx ",
          info.hi_ireqfreq, info.hi_flags);
  fprintf(stderr, "hi_hpet %d hi_timer %d\n", info.hi_hpet, info.hi_timer);
out:
  close(fd);
  return;
}


x86 assembly (clang, -O0):
<hpet_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
je     1175 <hpet_info+0x35>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1237 <hpet_info+0xf7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ba <hpet_info+0x7a>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1237 <hpet_info+0xf7>
mov    -0x24(%rbp),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11f5 <hpet_info+0xb5>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    122f <hpet_info+0xef>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpet_info>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jne    11b8 <hpet_info+0x78>
mov    %rsi,%rbx
mov    (%rsi),%rdi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11d5 <hpet_info+0x95>
mov    %eax,%ebp
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    0x2e57(%rip),%rbx
mov    (%rbx),%edi
test   %rax,%rax
js     11f5 <hpet_info+0xb5>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xebe(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
lea    0xed2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1203 <hpet_info+0xc3>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe30(%rip),%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.hpet_info = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"hpet_info: device-name\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_info: open of %s failed\0A\00"
@HPET_INFO = global i32 0
@.str.2 = [31 x i8] c"hpet_info: failed to get info\0A\00"
@.str.3 = [44 x i8] c"hpet_info: hi_irqfreq 0x%lx hi_flags 0x%lx \00"
@.str.4 = [24 x i8] c"hi_hpet %d hi_timer %d\0A\00"
define void @hpet_info(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.hpet_info
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %50
12: ; preds = %2
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %50
26: ; preds = %12
%27 = load i32, i32* %6
%28 = load i32, i32* @HPET_INFO
%29 = call i64 @ioctl(i32 %27, i32 %28, %struct.hpet_info* %5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %47
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %5, i32 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %5, i32 0, i32 1
%39 = load i32, i32* %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %39)
%41 = load i32, i32* @stderr
%42 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %5, i32 0, i32 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %5, i32 0, i32 3
%45 = load i32, i32* %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %45)
br label %47
47: ; preds = %34, %31
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %47, %20, %9
ret void
}

LLVM IR (-O2):
%struct.hpet_info = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"hpet_info: device-name\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_info: open of %s failed\0A\00"
@HPET_INFO = global i32 0
@.str.2 = [31 x i8] c"hpet_info: failed to get info\0A\00"
@.str.3 = [44 x i8] c"hpet_info: hi_irqfreq 0x%lx hi_flags 0x%lx \00"
@.str.4 = [24 x i8] c"hi_hpet %d hi_timer %d\0A\00"
define void @hpet_info(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.hpet_info
%4 = bitcast %struct.hpet_info* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %39
18: ; preds = %9
%19 = load i32, i32* @HPET_INFO
%20 = call i64 @ioctl(i32 %12, i32 %19, %struct.hpet_info* %3)
%21 = icmp slt i64 %20, 0
%22 = load i32, i32* @stderr
br i1 %21, label %23, label %25
23: ; preds = %18
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %37
25: ; preds = %18
%26 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %3, i64 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %29)
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %3, i64 0, i32 2
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %3, i64 0, i32 3
%35 = load i32, i32* %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %33, i32 %35)
br label %37
37: ; preds = %25, %23
%38 = call i32 @close(i32 %12)
br label %39
39: ; preds = %37, %14, %6
ret void
}