#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int GPIODirection(int, int);
int GPIORead(int);
int GPIOWrite(int, int);
int gpio_pin_state(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int repeat = 10;
  if (gpio_pin_state(23, 1) == -1 || gpio_pin_state(24, 1) == -1)
    return EXIT_FAILURE;
  if (-1 == GPIODirection(23, 1) || -1 == GPIODirection(24, 0))
    return (2);
  do {
    if (-1 == GPIOWrite(23, repeat % 2))
      return (3);
    printf("I'm reading %d in GPIO %d\n", GPIORead(24), 24);
    usleep(500 * 1000);
  } while (repeat--);
  (void)gpio_pin_state(23, 0);
  (void)gpio_pin_state(24, 0);
  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)
movl   $0xa,-0x14(%rbp)
mov    $0x17,%edi
mov    $0x1,%esi
call   1050 <gpio_pin_state@plt>
cmp    $0xffffffff,%eax
je     11ad <main+0x4d>
mov    $0x18,%edi
mov    $0x1,%esi
call   1050 <gpio_pin_state@plt>
cmp    $0xffffffff,%eax
jne    11be <main+0x5e>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1299 <main+0x139>
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11f7 <main+0x97>
mov    $0x18,%edi
xor    %esi,%esi
call   1030 <GPIODirection@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1203 <main+0xa3>
movl   $0x2,-0x4(%rbp)
jmp    1299 <main+0x139>
jmp    1208 <main+0xa8>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    $0x17,%edi
call   1060 <GPIOWrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    123a <main+0xda>
movl   $0x3,-0x4(%rbp)
jmp    1299 <main+0x139>
mov    $0x18,%edi
call   1070 <GPIORead@plt>
mov    %eax,%esi
lea    0xdb3(%rip),%rdi
mov    $0x18,%edx
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jne    1208 <main+0xa8>
mov    $0x17,%edi
xor    %esi,%esi
call   1050 <gpio_pin_state@plt>
mov    $0x18,%edi
xor    %esi,%esi
call   1050 <gpio_pin_state@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x17,%edi
mov    $0x1,%esi
call   1050 <gpio_pin_state@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xdd>
mov    $0x18,%edi
mov    $0x1,%esi
call   1050 <gpio_pin_state@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xdd>
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x2,%ebx
cmp    $0xffffffff,%eax
je     1246 <main+0xe6>
mov    $0x18,%edi
xor    %esi,%esi
call   1030 <GPIODirection@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xe6>
mov    $0xa,%ebp
lea    0xe2f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
and    $0x1,%esi
mov    $0x17,%edi
call   1060 <GPIOWrite@plt>
cmp    $0xffffffff,%eax
je     124f <main+0xef>
mov    $0x18,%edi
call   1070 <GPIORead@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x18,%edx
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
add    $0xffffffff,%ebp
jb     11e0 <main+0x80>
mov    $0x17,%edi
xor    %esi,%esi
call   1050 <gpio_pin_state@plt>
mov    $0x18,%edi
xor    %esi,%esi
call   1050 <gpio_pin_state@plt>
mov    0x2d9d(%rip),%rax
jmp    1244 <main+0xe4>
mov    0x2d9c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x3,%ebx
jmp    1246 <main+0xe6>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"I'm reading %d in GPIO %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%7 = call i32 @gpio_pin_state(i32 23, i32 1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @gpio_pin_state(i32 24, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %40
14: ; preds = %9
%15 = call i32 @GPIODirection(i32 23, i32 1)
%16 = icmp eq i32 -1, %15
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @GPIODirection(i32 24, i32 0)
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %21
20: ; preds = %17, %14
store i32 2, i32* %3
br label %40
21: ; preds = %17
br label %22
22: ; preds = %32, %21
%23 = load i32, i32* %6
%24 = srem i32 %23, 2
%25 = call i32 @GPIOWrite(i32 23, i32 %24)
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 3, i32* %3
br label %40
28: ; preds = %22
%29 = call i32 @GPIORead(i32 24)
%30 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %29, i32 24)
%31 = call i32 @usleep(i32 500000)
br label %32
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
%35 = icmp ne i32 %33, 0
br i1 %35, label %22, label %36
36: ; preds = %32
%37 = call i32 @gpio_pin_state(i32 23, i32 0)
%38 = call i32 @gpio_pin_state(i32 24, i32 0)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %3
br label %40
40: ; preds = %36, %27, %20, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"I'm reading %d in GPIO %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @gpio_pin_state(i32 23, i32 1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @gpio_pin_state(i32 24, i32 1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5, %2
%9 = load i32, i32* @EXIT_FAILURE
br label %31
10: ; preds = %5
%11 = tail call i32 @GPIODirection(i32 23, i32 1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %31, label %13
13: ; preds = %10
%14 = tail call i32 @GPIODirection(i32 24, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %31, label %16
16: ; preds = %13, %21
%17 = phi i32 [ %25, %21 ], [ 10, %13 ]
%18 = and i32 %17, 1
%19 = tail call i32 @GPIOWrite(i32 23, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = tail call i32 @GPIORead(i32 24)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %22, i32 24)
%24 = tail call i32 @usleep(i32 500000)
%25 = add nsw i32 %17, -1
%26 = icmp eq i32 %17, 0
br i1 %26, label %27, label %16
27: ; preds = %21
%28 = tail call i32 @gpio_pin_state(i32 23, i32 0)
%29 = tail call i32 @gpio_pin_state(i32 24, i32 0)
%30 = load i32, i32* @EXIT_SUCCESS
br label %31
31: ; preds = %16, %10, %13, %27, %8
%32 = phi i32 [ %9, %8 ], [ %30, %27 ], [ 2, %13 ], [ 2, %10 ], [ 3, %16 ]
ret i32 %32
}