#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 copLoadFile(int, char *, unsigned int *, unsigned int *,
                int /*<<< orphan*/);
int copRun(int, unsigned int, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int main(int argc, char *argv[]) {
  int cpuf = -1;
  int res;
  unsigned int entry_p, stack_p;
  if ((cpuf = open(argv[1], O_RDWR)) < 0) {
    printf("cannot open %s device (errno = %d)\n", argv[1], errno);
    exit(1);
  }
  res = copLoadFile(cpuf, argv[2], &entry_p, &stack_p, 0);
  if (res == 0)
    res = copRun(cpuf, entry_p, 0);
  return res;
}


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)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b6 <main+0x66>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1050 <copLoadFile@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ee <main+0x9e>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
call   1030 <copRun@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     119b <main+0x4b>
mov    %eax,%ebp
mov    0x10(%rbx),%rsi
mov    %rsp,%rdx
lea    0x4(%rsp),%rcx
mov    %eax,%edi
xor    %r8d,%r8d
call   1050 <copLoadFile@plt>
test   %eax,%eax
jne    1194 <main+0x44>
mov    (%rsp),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <copRun@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rsi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [36 x i8] c"cannot open %s device (errno = %d)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @copLoadFile(i32 %24, i8* %27, i32* %8, i32* %9, i32 0)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %23
%32 = load i32, i32* %6
%33 = load i32, i32* %8
%34 = call i32 @copRun(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %7
br label %35
35: ; preds = %31, %23
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [36 x i8] c"cannot open %s device (errno = %d)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %7
%14 = load i32, i32* @errno
%15 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @copLoadFile(i32 %10, i8* %19, i32* %3, i32* %4, i32 0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %3
%24 = call i32 @copRun(i32 %10, i32 %23, i32 0)
br label %25
25: ; preds = %22, %17
%26 = phi i32 [ %24, %22 ], [ %20, %17 ]
ret i32 %26
}