#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int init_gpio();
int /*<<< orphan*/ printf(char *, int);
int read_pin(int);
int set_pin_input(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int err = 0;
  int pin = 2;
  if (argc > 1) {
    pin = strtol(argv[1], NULL, 10);
  }
  err = init_gpio();
  if (err < 0) {
    fprintf(stderr, "init_gpio() failed\n");
    exit(EXIT_FAILURE);
  }
  err = set_pin_input(pin);
  if (err < 0) {
    fprintf(stderr, "set_pin_input() failed\n");
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 10; i++) {
    int val = read_pin(pin);
    printf("val = %i\n", val);
    sleep(1);
  }
}


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   $0x0,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <init_gpio@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fe <main+0x7e>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <set_pin_input@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1236 <main+0xb6>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1279 <main+0xf9>
mov    -0x18(%rbp),%edi
call   1040 <read_pin@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdd0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    123d <main+0xbd>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%ebx
cmp    $0x2,%edi
jl     11a0 <main+0x20>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <init_gpio@plt>
test   %eax,%eax
js     12dd <main+0x15d>
mov    %ebx,%edi
call   1070 <set_pin_input@plt>
test   %eax,%eax
js     12ef <main+0x16f>
mov    %ebx,%edi
call   1040 <read_pin@plt>
lea    0xe60(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1040 <read_pin@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd13(%rip),%rsi
jmp    12ff <main+0x17f>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"init_gpio() failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"set_pin_input() failed\0A\00"
@.str.2 = [10 x i8] c"val = %i\0A\00"
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 0, i32* %6
store i32 2, i32* %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i32* null, i32 10)
store i32 %16, i32* %7
br label %17
17: ; preds = %12, %2
%18 = call i32 (...) @init_gpio()
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = load i32, i32* %7
%28 = call i32 @set_pin_input(i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
store i32 0, i32* %8
br label %37
37: ; preds = %46, %36
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %7
%42 = call i32 @read_pin(i32 %41)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = call i32 @sleep(i32 1)
br label %46
46: ; preds = %40
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %37
49: ; preds = %37
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"init_gpio() failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 x i8] c"set_pin_input() failed\0A\00"
@.str.2 = [10 x i8] c"val = %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strtol(i8* nocapture %6, i32* null, i32 10)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 2, %2 ]
%10 = tail call i32 (...) @init_gpio()
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = tail call i32 @set_pin_input(i32 %9)
%19 = icmp slt i32 %18, 0
br i1 %19, label %51, label %20
20: ; preds = %17
%21 = tail call i32 @read_pin(i32 %9)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = tail call i32 @sleep(i32 1)
%24 = tail call i32 @read_pin(i32 %9)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = tail call i32 @sleep(i32 1)
%27 = tail call i32 @read_pin(i32 %9)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = tail call i32 @sleep(i32 1)
%30 = tail call i32 @read_pin(i32 %9)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = tail call i32 @sleep(i32 1)
%33 = tail call i32 @read_pin(i32 %9)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = tail call i32 @sleep(i32 1)
%36 = tail call i32 @read_pin(i32 %9)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = tail call i32 @sleep(i32 1)
%39 = tail call i32 @read_pin(i32 %9)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = tail call i32 @sleep(i32 1)
%42 = tail call i32 @read_pin(i32 %9)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = tail call i32 @sleep(i32 1)
%45 = tail call i32 @read_pin(i32 %9)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = tail call i32 @sleep(i32 1)
%48 = tail call i32 @read_pin(i32 %9)
%49 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = tail call i32 @sleep(i32 1)
ret i32 0
51: ; preds = %17
%52 = load i32, i32* @stderr
%53 = tail call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
}