#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
scalar_t__ ioctl(int, int, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
uint32_t __omap_32k_call(int nr) {
  static int fd;
  if (!fd)
    fd = open("/dev/timer32k", 0);
  if (fd) {
    uint32_t t;
    if (ioctl(fd, nr, &t) >= 0)
      return t;
  }
  return 0;
}


x86 assembly (clang, -O0):
<__omap_32k_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,0x2f02(%rip)
jne    114c <__omap_32k_call+0x2c>
lea    0xec1(%rip),%rdi
xor    %esi,%esi
call   1040 <open@plt>
mov    %eax,0x2ee8(%rip)
cmpl   $0x0,0x2ee1(%rip)
je     1185 <__omap_32k_call+0x65>
mov    0x2ed5(%rip),%edi
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jl     1180 <__omap_32k_call+0x60>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <__omap_32k_call+0x6c>
jmp    1185 <__omap_32k_call+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__omap_32k_call>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2f07(%rip),%edi
test   %edi,%edi
jne    114b <__omap_32k_call+0x2b>
lea    0xec8(%rip),%rdi
xor    %esi,%esi
call   1040 <open@plt>
mov    %eax,%edi
mov    %eax,0x2eed(%rip)
test   %eax,%eax
je     1162 <__omap_32k_call+0x42>
lea    0xc(%rsp),%rdx
mov    %ebx,%esi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1162 <__omap_32k_call+0x42>
mov    0xc(%rsp),%eax
jmp    1164 <__omap_32k_call+0x44>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__omap_32k_call.fd = internal global i32 0
@.str = [14 x i8] c"/dev/timer32k\00"
define i32 @__omap_32k_call(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @__omap_32k_call.fd
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %8, i32* @__omap_32k_call.fd
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* @__omap_32k_call.fd
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* @__omap_32k_call.fd
%14 = load i32, i32* %3
%15 = call i64 @ioctl(i32 %13, i32 %14, i32* %4)
%16 = icmp sge i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %21
19: ; preds = %12
br label %20
20: ; preds = %19, %9
store i32 0, i32* %2
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@__omap_32k_call.fd = internal unnamed_addr global i32 0
@.str = [14 x i8] c"/dev/timer32k\00"
define i32 @__omap_32k_call(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @__omap_32k_call.fd
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %6, i32* @__omap_32k_call.fd
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1, %5
%9 = phi i32 [ %6, %5 ], [ %3, %1 ]
%10 = bitcast i32* %2 to i8*
%11 = call i64 @ioctl(i32 %9, i32 %0, i32* %2)
%12 = icmp slt i64 %11, 0
%13 = load i32, i32* %2
br i1 %12, label %14, label %15
14: ; preds = %8, %5
br label %15
15: ; preds = %8, %14
%16 = phi i32 [ %13, %8 ], [ 0, %14 ]
ret i32 %16
}