#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 timezone {
  int dummy;
};
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct pollfd {
  int fd;
  long revents;
  int /*<<< orphan*/ events;
};
struct hpet_info {
  long hi_flags;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ HPET_EPI;
int /*<<< orphan*/ HPET_IE_ON;
int /*<<< orphan*/ HPET_INFO;
int /*<<< orphan*/ HPET_IRQFREQ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ POLLIN;
void *atoi(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char const *, int /*<<< orphan*/);
scalar_t__ poll(struct pollfd *, int, int);
int read(int, long *, int);
int /*<<< orphan*/ stderr;
void hpet_poll(int argc, const char **argv) {
  unsigned long freq;
  int iterations, i, fd;
  struct pollfd pfd;
  struct hpet_info info;
  struct timeval stv, etv;
  struct timezone tz;
  long usec;
  if (argc != 3) {
    fprintf(stderr, "hpet_poll: device-name freq iterations\n");
    return;
  }
  freq = atoi(argv[1]);
  iterations = atoi(argv[2]);
  fd = open(argv[0], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "hpet_poll: open of %s failed\n", argv[0]);
    return;
  }
  if (ioctl(fd, HPET_IRQFREQ, freq) < 0) {
    fprintf(stderr, "hpet_poll: HPET_IRQFREQ failed\n");
    goto out;
  }
  if (ioctl(fd, HPET_INFO, &info) < 0) {
    fprintf(stderr, "hpet_poll: failed to get info\n");
    goto out;
  }
  fprintf(stderr, "hpet_poll: info.hi_flags 0x%lx\n", info.hi_flags);
  if (info.hi_flags && (ioctl(fd, HPET_EPI, 0) < 0)) {
    fprintf(stderr, "hpet_poll: HPET_EPI failed\n");
    goto out;
  }
  if (ioctl(fd, HPET_IE_ON, 0) < 0) {
    fprintf(stderr, "hpet_poll, HPET_IE_ON failed\n");
    goto out;
  }
  pfd.fd = fd;
  pfd.events = POLLIN;
  for (i = 0; i < iterations; i++) {
    pfd.revents = 0;
    gettimeofday(&stv, &tz);
    if (poll(&pfd, 1, -1) < 0) {
      fprintf(stderr, "hpet_poll: poll failed\n");
    } else {
      long data;
      gettimeofday(&etv, &tz);
      usec = stv.tv_sec * 1000000 + stv.tv_usec;
      usec = (etv.tv_sec * 1000000 + etv.tv_usec) - usec;
      fprintf(stderr, "hpet_poll: expired time = 0x%lx\n", usec);
      fprintf(stderr, "hpet_poll: revents = 0x%x\n", pfd.revents);
      if (read(fd, &data, sizeof(data)) != sizeof(data)) {
        fprintf(stderr, "hpet_poll: read failed\n");
      } else
        fprintf(stderr, "hpet_poll: data 0x%lx\n", data);
    }
  }
out:
  close(fd);
  return;
}


x86 assembly (clang, -O0):
<hpet_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     11b5 <hpet_poll+0x35>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1484 <hpet_poll+0x304>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    121b <hpet_poll+0x9b>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1484 <hpet_poll+0x304>
mov    -0x24(%rbp),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1258 <hpet_poll+0xd8>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    147c <hpet_poll+0x2fc>
mov    -0x24(%rbp),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1295 <hpet_poll+0x115>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    147c <hpet_poll+0x2fc>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x48(%rbp)
je     12f6 <hpet_poll+0x176>
mov    -0x24(%rbp),%edi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    12f6 <hpet_poll+0x176>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    147c <hpet_poll+0x2fc>
mov    -0x24(%rbp),%edi
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1331 <hpet_poll+0x1b1>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    147c <hpet_poll+0x2fc>
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1477 <hpet_poll+0x2f7>
movq   $0x0,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <gettimeofday@plt>
lea    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1080 <poll@plt>
cmp    $0x0,%rax
jge    13a4 <hpet_poll+0x224>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1464 <hpet_poll+0x2e4>
lea    -0x58(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x50(%rbp),%eax
add    -0x4c(%rbp),%eax
cltq
mov    %rax,-0x68(%rbp)
imul   $0xf4240,-0x58(%rbp),%eax
add    -0x54(%rbp),%eax
cltq
sub    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd14(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cltq
cmp    $0x8,%rax
je     1444 <hpet_poll+0x2c4>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    145f <hpet_poll+0x2df>
mov    0x2b75(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rdx
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1464 <hpet_poll+0x2e4>
jmp    1469 <hpet_poll+0x2e9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    134a <hpet_poll+0x1ca>
jmp    147c <hpet_poll+0x2fc>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpet_poll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jne    129b <hpet_poll+0x11b>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %rax,%r14
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     13bc <hpet_poll+0x23c>
mov    %eax,%r13d
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %rax,%rax
js     13e5 <hpet_poll+0x265>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r13d,%edi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x2db3(%rip),%rbp
mov    0x0(%rbp),%edi
test   %rax,%rax
js     13f7 <hpet_poll+0x277>
mov    0x18(%rsp),%rdx
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpq   $0x0,0x18(%rsp)
je     1252 <hpet_poll+0xd2>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %rax,%rax
js     140c <hpet_poll+0x28c>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %rax,%rax
js     1400 <hpet_poll+0x280>
mov    %r13d,0x30(%rsp)
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
test   %ebx,%ebx
jle    141d <hpet_poll+0x29d>
lea    0x10(%rsp),%r14
lea    0x28(%rsp),%r15
lea    0x30(%rsp),%r12
jmp    12dc <hpet_poll+0x15c>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
mov    0x20(%rsp),%rdx
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0xffffffff,%ebx
je     141d <hpet_poll+0x29d>
movq   $0x0,0x38(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <gettimeofday@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1080 <poll@plt>
test   %rax,%rax
js     13a0 <hpet_poll+0x220>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1030 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x14(%rsp),%rcx
add    %rax,%rcx
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rdx
add    %rax,%rdx
sub    %rcx,%rdx
mov    0x0(%rbp),%edi
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x38(%rsp),%rdx
lea    0xdb5(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    0x0(%rbp),%edi
cmp    $0x8,%eax
je     12c0 <hpet_poll+0x140>
lea    0xda4(%rip),%rsi
jmp    13aa <hpet_poll+0x22a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
lea    0xd35(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0xffffffff,%ebx
jne    12dc <hpet_poll+0x15c>
jmp    141d <hpet_poll+0x29d>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc58(%rip),%rsi
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
lea    0xc51(%rip),%rsi
jmp    1416 <hpet_poll+0x296>
lea    0xc68(%rip),%rsi
jmp    1416 <hpet_poll+0x296>
mov    0x0(%rbp),%edi
lea    0xcb7(%rip),%rsi
jmp    1416 <hpet_poll+0x296>
mov    0x0(%rbp),%edi
lea    0xc8f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13d,%edi
call   1050 <close@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i64, i32 }
%struct.hpet_info = type { i64 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@stderr = global i32 0
@.str = [40 x i8] c"hpet_poll: device-name freq iterations\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_poll: open of %s failed\0A\00"
@HPET_IRQFREQ = global i32 0
@.str.2 = [32 x i8] c"hpet_poll: HPET_IRQFREQ failed\0A\00"
@HPET_INFO = global i32 0
@.str.3 = [31 x i8] c"hpet_poll: failed to get info\0A\00"
@.str.4 = [32 x i8] c"hpet_poll: info.hi_flags 0x%lx\0A\00"
@HPET_EPI = global i32 0
@.str.5 = [28 x i8] c"hpet_poll: HPET_EPI failed\0A\00"
@HPET_IE_ON = global i32 0
@.str.6 = [30 x i8] c"hpet_poll, HPET_IE_ON failed\0A\00"
@POLLIN = global i32 0
@.str.7 = [24 x i8] c"hpet_poll: poll failed\0A\00"
@.str.8 = [33 x i8] c"hpet_poll: expired time = 0x%lx\0A\00"
@.str.9 = [27 x i8] c"hpet_poll: revents = 0x%x\0A\00"
@.str.10 = [24 x i8] c"hpet_poll: read failed\0A\00"
@.str.11 = [23 x i8] c"hpet_poll: data 0x%lx\0A\00"
define void @hpet_poll(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.pollfd
%10 = alloca %struct.hpet_info
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
%13 = alloca %struct.timezone
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %148
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @atoi(i8* %24)
%26 = ptrtoint i8* %25 to i64
store i64 %26, i64* %5
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i8* @atoi(i8* %29)
%31 = ptrtoint i8* %30 to i32
store i32 %31, i32* %6
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %21
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %148
45: ; preds = %21
%46 = load i32, i32* %8
%47 = load i32, i32* @HPET_IRQFREQ
%48 = load i64, i64* %5
%49 = call i64 (i32, i32, ...) @ioctl(i32 %46, i32 %47, i64 %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %145
54: ; preds = %45
%55 = load i32, i32* %8
%56 = load i32, i32* @HPET_INFO
%57 = call i64 (i32, i32, ...) @ioctl(i32 %55, i32 %56, %struct.hpet_info* %10)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %145
62: ; preds = %54
%63 = load i32, i32* @stderr
%64 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %10, i32 0, i32 0
%65 = load i64, i64* %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i64 %65)
%67 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %10, i32 0, i32 0
%68 = load i64, i64* %67
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %78
70: ; preds = %62
%71 = load i32, i32* %8
%72 = load i32, i32* @HPET_EPI
%73 = call i64 (i32, i32, ...) @ioctl(i32 %71, i32 %72, i32 0)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %145
78: ; preds = %70, %62
%79 = load i32, i32* %8
%80 = load i32, i32* @HPET_IE_ON
%81 = call i64 (i32, i32, ...) @ioctl(i32 %79, i32 %80, i32 0)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %145
86: ; preds = %78
%87 = load i32, i32* %8
%88 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 0
store i32 %87, i32* %88
%89 = load i32, i32* @POLLIN
%90 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 2
store i32 %89, i32* %90
store i32 0, i32* %7
br label %91
91: ; preds = %141, %86
%92 = load i32, i32* %7
%93 = load i32, i32* %6
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %144
95: ; preds = %91
%96 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 1
store i64 0, i64* %96
%97 = call i32 @gettimeofday(%struct.timeval* %11, %struct.timezone* %13)
%98 = call i64 @poll(%struct.pollfd* %9, i32 1, i32 -1)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %95
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %140
103: ; preds = %95
%104 = call i32 @gettimeofday(%struct.timeval* %12, %struct.timezone* %13)
%105 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%106 = load i32, i32* %105
%107 = mul nsw i32 %106, 1000000
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%109 = load i32, i32* %108
%110 = add nsw i32 %107, %109
%111 = sext i32 %110 to i64
store i64 %111, i64* %14
%112 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%113 = load i32, i32* %112
%114 = mul nsw i32 %113, 1000000
%115 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%116 = load i32, i32* %115
%117 = add nsw i32 %114, %116
%118 = sext i32 %117 to i64
%119 = load i64, i64* %14
%120 = sub nsw i64 %118, %119
store i64 %120, i64* %14
%121 = load i32, i32* @stderr
%122 = load i64, i64* %14
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 %122)
%124 = load i32, i32* @stderr
%125 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 1
%126 = load i64, i64* %125
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %126)
%128 = load i32, i32* %8
%129 = call i32 @read(i32 %128, i64* %15, i32 8)
%130 = sext i32 %129 to i64
%131 = icmp ne i64 %130, 8
br i1 %131, label %132, label %135
132: ; preds = %103
%133 = load i32, i32* @stderr
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %139
135: ; preds = %103
%136 = load i32, i32* @stderr
%137 = load i64, i64* %15
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i64 %137)
br label %139
139: ; preds = %135, %132
br label %140
140: ; preds = %139, %100
br label %141
141: ; preds = %140
%142 = load i32, i32* %7
%143 = add nsw i32 %142, 1
store i32 %143, i32* %7
br label %91
144: ; preds = %91
br label %145
145: ; preds = %144, %83, %75, %59, %51
%146 = load i32, i32* %8
%147 = call i32 @close(i32 %146)
br label %148
148: ; preds = %145, %39, %18
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64, i32 }
%struct.hpet_info = type { i64 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@stderr = global i32 0
@.str = [40 x i8] c"hpet_poll: device-name freq iterations\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [30 x i8] c"hpet_poll: open of %s failed\0A\00"
@HPET_IRQFREQ = global i32 0
@.str.2 = [32 x i8] c"hpet_poll: HPET_IRQFREQ failed\0A\00"
@HPET_INFO = global i32 0
@.str.3 = [31 x i8] c"hpet_poll: failed to get info\0A\00"
@.str.4 = [32 x i8] c"hpet_poll: info.hi_flags 0x%lx\0A\00"
@HPET_EPI = global i32 0
@.str.5 = [28 x i8] c"hpet_poll: HPET_EPI failed\0A\00"
@HPET_IE_ON = global i32 0
@.str.6 = [30 x i8] c"hpet_poll, HPET_IE_ON failed\0A\00"
@POLLIN = global i32 0
@.str.7 = [24 x i8] c"hpet_poll: poll failed\0A\00"
@.str.8 = [33 x i8] c"hpet_poll: expired time = 0x%lx\0A\00"
@.str.9 = [27 x i8] c"hpet_poll: revents = 0x%x\0A\00"
@.str.10 = [24 x i8] c"hpet_poll: read failed\0A\00"
@.str.11 = [23 x i8] c"hpet_poll: data 0x%lx\0A\00"
define void @hpet_poll(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.pollfd
%4 = alloca %struct.hpet_info
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timezone
%8 = alloca i64
%9 = bitcast %struct.pollfd* %3 to i8*
%10 = bitcast %struct.hpet_info* %4 to i8*
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast %struct.timeval* %6 to i8*
%13 = bitcast %struct.timezone* %7 to i8*
%14 = icmp eq i32 %0, 3
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %122
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i8* @atoi(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i8* @atoi(i8* %23)
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
%27 = load i8*, i8** %1
%28 = load i32, i32* @O_RDONLY
%29 = tail call i32 @open(i8* %27, i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %1
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %122
35: ; preds = %18
%36 = ptrtoint i8* %21 to i64
%37 = load i32, i32* @HPET_IRQFREQ
%38 = tail call i64 (i32, i32, ...) @ioctl(i32 %29, i32 %37, i64 %36)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %120
43: ; preds = %35
%44 = load i32, i32* @HPET_INFO
%45 = call i64 (i32, i32, ...) @ioctl(i32 %29, i32 %44, %struct.hpet_info* %4)
%46 = icmp slt i64 %45, 0
%47 = load i32, i32* @stderr
br i1 %46, label %48, label %50
48: ; preds = %43
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %120
50: ; preds = %43
%51 = getelementptr inbounds %struct.hpet_info, %struct.hpet_info* %4, i64 0, i32 0
%52 = load i64, i64* %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i64 %52)
%54 = load i64, i64* %51
%55 = icmp eq i64 %54, 0
br i1 %55, label %63, label %56
56: ; preds = %50
%57 = load i32, i32* @HPET_EPI
%58 = call i64 (i32, i32, ...) @ioctl(i32 %29, i32 %57, i32 0)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %120
63: ; preds = %56, %50
%64 = load i32, i32* @HPET_IE_ON
%65 = call i64 (i32, i32, ...) @ioctl(i32 %29, i32 %64, i32 0)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %120
70: ; preds = %63
%71 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 0
store i32 %29, i32* %71
%72 = load i32, i32* @POLLIN
%73 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 2
store i32 %72, i32* %73
%74 = icmp sgt i32 %26, 0
br i1 %74, label %75, label %120
75: ; preds = %70
%76 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 1
%77 = bitcast i64* %8 to i8*
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
br label %82
82: ; preds = %75, %117
%83 = phi i32 [ 0, %75 ], [ %118, %117 ]
store i64 0, i64* %76
%84 = call i32 @gettimeofday(%struct.timeval* %5, %struct.timezone* %7)
%85 = call i64 @poll(%struct.pollfd* %3, i32 1, i32 -1)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %82
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %117
90: ; preds = %82
%91 = call i32 @gettimeofday(%struct.timeval* %6, %struct.timezone* %7)
%92 = load i32, i32* %78
%93 = mul nsw i32 %92, 1000000
%94 = load i32, i32* %79
%95 = add nsw i32 %93, %94
%96 = sext i32 %95 to i64
%97 = load i32, i32* %80
%98 = mul nsw i32 %97, 1000000
%99 = load i32, i32* %81
%100 = add nsw i32 %98, %99
%101 = sext i32 %100 to i64
%102 = sub nsw i64 %101, %96
%103 = load i32, i32* @stderr
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 %102)
%105 = load i32, i32* @stderr
%106 = load i64, i64* %76
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %106)
%108 = call i32 @read(i32 %29, i64* %8, i32 8)
%109 = icmp eq i32 %108, 8
%110 = load i32, i32* @stderr
br i1 %109, label %113, label %111
111: ; preds = %90
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %116
113: ; preds = %90
%114 = load i64, i64* %8
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i64 %114)
br label %116
116: ; preds = %113, %111
br label %117
117: ; preds = %87, %116
%118 = add nuw nsw i32 %83, 1
%119 = icmp eq i32 %118, %26
br i1 %119, label %120, label %82
120: ; preds = %117, %70, %67, %60, %48, %40
%121 = call i32 @close(i32 %29)
br label %122
122: ; preds = %120, %31, %15
ret void
}