#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ cpu_meminfo_test(int, int);
int /*<<< orphan*/ cpustat_test(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ipmi_test(int);
int /*<<< orphan*/ ipmi_timeout_test(int);
int /*<<< orphan*/ ipmi_wrapper_test();
int /*<<< orphan*/ msr_read_test(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ msr_write_test(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *driver = "/dev/measure";
  printf("=====Driver Tester=====\n");
  int fildes = open(driver, O_RDWR);
  if (fildes < 0) {
    fprintf(stderr, "Cannot open driver \"%s\".\n", driver);
    exit(EXIT_FAILURE);
  }
  cpustat_test(fildes);
  msr_read_test(fildes, 0x0000000000000000, 0);
  msr_read_test(fildes, 0x0001000000000000, 0);
  msr_write_test(fildes, 0x0000000000000000);
  msr_write_test(fildes, 0x0001000000000000);
  ipmi_test(fildes);
  ipmi_wrapper_test();
  cpu_meminfo_test(fildes, 8192);
  ipmi_timeout_test(fildes);
  close(fildes);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe23(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1233 <main+0x73>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe06(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1030 <cpustat_test@plt>
mov    -0x1c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10e0 <msr_read_test@plt>
mov    -0x1c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10e0 <msr_read_test@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <msr_write_test@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <msr_write_test@plt>
mov    -0x1c(%rbp),%edi
call   1090 <ipmi_test@plt>
mov    $0x0,%al
call   1060 <ipmi_wrapper_test@plt>
mov    -0x1c(%rbp),%edi
mov    $0x2000,%esi
call   1070 <cpu_meminfo_test@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <ipmi_timeout_test@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe5f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     124a <main+0x8a>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <cpustat_test@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <msr_read_test@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <msr_read_test@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <msr_write_test@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <msr_write_test@plt>
mov    %ebx,%edi
call   1090 <ipmi_test@plt>
xor    %eax,%eax
call   1060 <ipmi_wrapper_test@plt>
mov    %ebx,%edi
mov    $0x2000,%esi
call   1070 <cpu_meminfo_test@plt>
mov    %ebx,%edi
call   10b0 <ipmi_timeout_test@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
lea    0xd9f(%rip),%rdx
call   10a0 <fprintf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/measure\00"
@.str.1 = [25 x i8] c"=====Driver Tester=====\0A\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Cannot open driver \22%s\22.\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8*, i8** %6
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %6
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* %7
%22 = call i32 @cpustat_test(i32 %21)
%23 = load i32, i32* %7
%24 = call i32 @msr_read_test(i32 %23, i32 0, i32 0)
%25 = load i32, i32* %7
%26 = call i32 @msr_read_test(i32 %25, i32 0, i32 0)
%27 = load i32, i32* %7
%28 = call i32 @msr_write_test(i32 %27, i32 0)
%29 = load i32, i32* %7
%30 = call i32 @msr_write_test(i32 %29, i32 0)
%31 = load i32, i32* %7
%32 = call i32 @ipmi_test(i32 %31)
%33 = call i32 (...) @ipmi_wrapper_test()
%34 = load i32, i32* %7
%35 = call i32 @cpu_meminfo_test(i32 %34, i32 8192)
%36 = load i32, i32* %7
%37 = call i32 @ipmi_timeout_test(i32 %36)
%38 = load i32, i32* %7
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/measure\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Cannot open driver \22%s\22.\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"=====Driver Tester=====\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 @cpustat_test(i32 %5)
%14 = tail call i32 @msr_read_test(i32 %5, i32 0, i32 0)
%15 = tail call i32 @msr_read_test(i32 %5, i32 0, i32 0)
%16 = tail call i32 @msr_write_test(i32 %5, i32 0)
%17 = tail call i32 @msr_write_test(i32 %5, i32 0)
%18 = tail call i32 @ipmi_test(i32 %5)
%19 = tail call i32 (...) @ipmi_wrapper_test()
%20 = tail call i32 @cpu_meminfo_test(i32 %5, i32 8192)
%21 = tail call i32 @ipmi_timeout_test(i32 %5)
%22 = tail call i32 @close(i32 %5)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}