#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_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int trace_gettotalnum() {
  int fd;
  fd = open("/dev/hapara_trace", O_RDWR);
  if (fd == -1)
    return -1;
  int ioctl_ret = ioctl(fd, _IO('t', 2));
  close(fd);
  return ioctl_ret;
}


x86 assembly (clang, -O0):
<trace_gettotalnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1176 <trace_gettotalnum+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <trace_gettotalnum+0x66>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x74,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_gettotalnum>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1184 <trace_gettotalnum+0x44>
mov    %eax,%ebx
mov    $0x74,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
jmp    1189 <trace_gettotalnum+0x49>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/dev/hapara_trace\00"
@O_RDWR = global i32 0
define i32 @trace_gettotalnum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %16
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @_IO(i8 signext 116, i32 2)
%12 = call i32 @ioctl(i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %3
store i32 %15, i32* %1
br label %16
16: ; preds = %9, %8
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/hapara_trace\00"
@O_RDWR = global i32 0
define i32 @trace_gettotalnum() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @_IO(i8 signext 116, i32 2)
%6 = tail call i32 @ioctl(i32 %2, i32 %5)
%7 = tail call i32 @close(i32 %2)
br label %8
8: ; preds = %0, %4
%9 = phi i32 [ %6, %4 ], [ -1, %0 ]
ret i32 %9
}