#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*/ FILE;

/* Variables and functions */
int evemu_device(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int device(int argc, char *argv[]) {
  FILE *fp;
  int ret;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <dev.prop>\n", argv[0]);
    return -1;
  }
  fp = fopen(argv[1], "r");
  if (!fp) {
    fprintf(stderr, "error: could not open file (%m)\n");
    return -1;
  }
  ret = evemu_device(fp);
  if (ret <= 0) {
    fprintf(stderr, "error: could not create device: %d\n", ret);
    return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1183 <device+0x43>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <device+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <device+0x89>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <device+0xd5>
mov    -0x18(%rbp),%rdi
call   1030 <evemu_device@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1205 <device+0xc5>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <device+0xd5>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device>:
push   %rbx
cmp    $0x1,%edi
jg     1162 <device+0x22>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c4 <device+0x84>
mov    0x8(%rsi),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1192 <device+0x52>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <evemu_device@plt>
test   %eax,%eax
jle    11ab <device+0x6b>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c4 <device+0x84>
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7e(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <dev.prop>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error: could not open file (%m)\0A\00"
@.str.3 = [36 x i8] c"error: could not create device: %d\0A\00"
define i32 @device(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
26: ; preds = %16
%27 = load i32*, i32** %6
%28 = call i32 @evemu_device(i32* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i32, i32* %7
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 -1, i32* %3
br label %38
35: ; preds = %26
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %31, %23, %10
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <dev.prop>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error: could not open file (%m)\0A\00"
@.str.3 = [36 x i8] c"error: could not create device: %d\0A\00"
define i32 @device(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %24
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %24
16: ; preds = %8
%17 = tail call i32 @evemu_device(i32* %11)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %24
22: ; preds = %16
%23 = tail call i32 @fclose(i32* %11)
br label %24
24: ; preds = %22, %19, %13, %4
%25 = phi i32 [ -1, %4 ], [ -1, %19 ], [ 0, %22 ], [ -1, %13 ]
ret i32 %25
}