#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*/ close_devbox_io(int);
int /*<<< orphan*/ devbox_7seg_write(int, int);
int devbox_get_sw(int);
int /*<<< orphan*/ devbox_set_7seg(int, int, int);
int /*<<< orphan*/ devbox_set_led(int, int);
int open_devbox_io();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int x = open_devbox_io();
  if (x < 0)
    printf("FAIL!\n");
  else {
    printf("SUCCESS %x\n", x);
    int q = devbox_get_sw(x);
    printf("Switches= %x\n", q);
    devbox_set_led(x, q);
    devbox_set_7seg(x, 0, 123);
    devbox_set_7seg(x, 1, 21);
    devbox_set_7seg(x, 2, 123);
    devbox_set_7seg(x, 3, 123);
    devbox_7seg_write(x, 0xaf7701);
    close_devbox_io(x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <open_devbox_io@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a6 <main+0x36>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1238 <main+0xc8>
mov    -0x8(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <devbox_get_sw@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <devbox_set_led@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x7b,%edx
call   1090 <devbox_set_7seg@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0x15,%edx
call   1090 <devbox_set_7seg@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
mov    $0x7b,%edx
call   1090 <devbox_set_7seg@plt>
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
mov    $0x7b,%edx
call   1090 <devbox_set_7seg@plt>
mov    -0x8(%rbp),%edi
mov    $0xaf7701,%esi
call   1030 <devbox_7seg_write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close_devbox_io@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <open_devbox_io@plt>
test   %eax,%eax
js     121c <main+0x9c>
mov    %eax,%ebx
lea    0xe65(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <devbox_get_sw@plt>
mov    %eax,%ebp
lea    0xe58(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <devbox_set_led@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x7b,%edx
call   10a0 <devbox_set_7seg@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x15,%edx
call   10a0 <devbox_set_7seg@plt>
mov    %ebx,%edi
mov    $0x2,%esi
mov    $0x7b,%edx
call   10a0 <devbox_set_7seg@plt>
mov    %ebx,%edi
mov    $0x3,%esi
mov    $0x7b,%edx
call   10a0 <devbox_set_7seg@plt>
mov    %ebx,%edi
mov    $0xaf7701,%esi
call   1030 <devbox_7seg_write@plt>
mov    %ebx,%edi
call   1040 <close_devbox_io@plt>
jmp    1228 <main+0xa8>
lea    0xdf7(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"FAIL!\0A\00"
@.str.1 = [12 x i8] c"SUCCESS %x\0A\00"
@.str.2 = [14 x i8] c"Switches= %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @open_devbox_io()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @devbox_get_sw(i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i32 @devbox_set_led(i32 %16, i32 %17)
%19 = load i32, i32* %2
%20 = call i32 @devbox_set_7seg(i32 %19, i32 0, i32 123)
%21 = load i32, i32* %2
%22 = call i32 @devbox_set_7seg(i32 %21, i32 1, i32 21)
%23 = load i32, i32* %2
%24 = call i32 @devbox_set_7seg(i32 %23, i32 2, i32 123)
%25 = load i32, i32* %2
%26 = call i32 @devbox_set_7seg(i32 %25, i32 3, i32 123)
%27 = load i32, i32* %2
%28 = call i32 @devbox_7seg_write(i32 %27, i32 11499265)
%29 = load i32, i32* %2
%30 = call i32 @close_devbox_io(i32 %29)
br label %31
31: ; preds = %9, %7
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"SUCCESS %x\0A\00"
@.str.2 = [14 x i8] c"Switches= %x\0A\00"
@str = [6 x i8] c"FAIL!\00"
define i32 @main() {
%1 = tail call i32 (...) @open_devbox_io()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %16
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%7 = tail call i32 @devbox_get_sw(i32 %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @devbox_set_led(i32 %1, i32 %7)
%10 = tail call i32 @devbox_set_7seg(i32 %1, i32 0, i32 123)
%11 = tail call i32 @devbox_set_7seg(i32 %1, i32 1, i32 21)
%12 = tail call i32 @devbox_set_7seg(i32 %1, i32 2, i32 123)
%13 = tail call i32 @devbox_set_7seg(i32 %1, i32 3, i32 123)
%14 = tail call i32 @devbox_7seg_write(i32 %1, i32 11499265)
%15 = tail call i32 @close_devbox_io(i32 %1)
br label %16
16: ; preds = %5, %3
ret i32 0
}