#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*/ delay(int);
int gpio_get_value(int);
int /*<<< orphan*/ gpio_set_mode(int, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
void wait_for_result() {
  int ack;
  gpio_set_mode(38, "in");
  int i;
  for (i = 0; i < 100; i++) {
    delay(20);
    ack = gpio_get_value(38);
    if (ack == 0) {
      printf("Sensor Data Ready\n");
      break;
    }
  }
  if (ack == 1) {
    perror("ACK error 2");
  }
}


x86 assembly (clang, -O0):
<wait_for_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x26,%edi
lea    0xe9c(%rip),%rsi
call   1050 <gpio_set_mode@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11bf <wait_for_result+0x6f>
mov    $0x14,%edi
call   1060 <delay@plt>
mov    $0x26,%edi
call   1040 <gpio_get_value@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11ac <wait_for_result+0x5c>
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
jmp    11bf <wait_for_result+0x6f>
jmp    11b1 <wait_for_result+0x61>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1170 <wait_for_result+0x20>
cmpl   $0x1,-0x4(%rbp)
jne    11d5 <wait_for_result+0x85>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_result>:
push   %rbx
lea    0xea8(%rip),%rsi
mov    $0x26,%edi
call   1050 <gpio_set_mode@plt>
mov    $0x64,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x14,%edi
call   1060 <delay@plt>
mov    $0x26,%edi
call   1040 <gpio_get_value@plt>
test   %eax,%eax
je     1194 <wait_for_result+0x44>
add    $0xffffffff,%ebx
jne    1170 <wait_for_result+0x20>
cmp    $0x1,%eax
je     11a1 <wait_for_result+0x51>
pop    %rbx
ret
lea    0xe74(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe5b(%rip),%rdi
pop    %rbx
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"in\00"
@.str.1 = [19 x i8] c"Sensor Data Ready\0A\00"
@.str.2 = [12 x i8] c"ACK error 2\00"
define void @wait_for_result() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @gpio_set_mode(i32 38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 100
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = call i32 @delay(i32 20)
%9 = call i32 @gpio_get_value(i32 38)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %18
14: ; preds = %7
br label %15
15: ; preds = %14
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %4
18: ; preds = %12, %4
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"in\00"
@.str.2 = [12 x i8] c"ACK error 2\00"
@str = [18 x i8] c"Sensor Data Ready\00"
define void @wait_for_result() {
%1 = tail call i32 @gpio_set_mode(i32 38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 100
br i1 %4, label %12, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i32 @delay(i32 20)
%8 = tail call i32 @gpio_get_value(i32 38)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %2
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %2
%13 = icmp eq i32 %8, 1
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %10, %14, %12
ret void
}