#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 */
unsigned int gpio_read(void *, int);
int /*<<< orphan*/ gpio_write(void *, int, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ read(int, void *, int);
int /*<<< orphan*/ write(int, void *, int);
void wait_for_interrupt(int fd, void *gpio_ptr) {
  int pending = 0;
  int reenable = 1;
  unsigned int reg;
  int sum = 0, i;
  read(fd, (void *)&pending, sizeof(int));
  reg = gpio_read(gpio_ptr, 0x120);
  if (reg)
    gpio_write(gpio_ptr, 0x120, 2);
  reg = gpio_read(gpio_ptr, 0x08);
  printf("GPIO_DATA2_OFFSET: 0x%d\n", reg);
  write(fd, (void *)&reenable, sizeof(int));
}


x86 assembly (clang, -O0):
<wait_for_interrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%rdi
mov    $0x120,%esi
call   1070 <gpio_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11b3 <wait_for_interrupt+0x63>
mov    -0x10(%rbp),%rdi
mov    $0x120,%esi
mov    $0x2,%edx
call   1050 <gpio_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <gpio_read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_interrupt>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
movl   $0x1,(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %rbx,%rdi
mov    $0x120,%esi
call   1070 <gpio_read@plt>
test   %eax,%eax
je     1199 <wait_for_interrupt+0x49>
mov    %rbx,%rdi
mov    $0x120,%esi
mov    $0x2,%edx
call   1050 <gpio_write@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <gpio_read@plt>
lea    0xe53(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"GPIO_DATA2_OFFSET: 0x%d\0A\00"
define void @wait_for_interrupt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 1, i32* %6
store i32 0, i32* %8
%10 = load i32, i32* %3
%11 = bitcast i32* %5 to i8*
%12 = call i32 @read(i32 %10, i8* %11, i32 4)
%13 = load i8*, i8** %4
%14 = call i32 @gpio_read(i8* %13, i32 288)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @gpio_write(i8* %18, i32 288, i32 2)
br label %20
20: ; preds = %17, %2
%21 = load i8*, i8** %4
%22 = call i32 @gpio_read(i8* %21, i32 8)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
%26 = bitcast i32* %6 to i8*
%27 = call i32 @write(i32 %25, i8* %26, i32 4)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"GPIO_DATA2_OFFSET: 0x%d\0A\00"
define void @wait_for_interrupt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%7 = call i32 @read(i32 %0, i8* %5, i32 4)
%8 = tail call i32 @gpio_read(i8* %1, i32 288)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @gpio_write(i8* %1, i32 288, i32 2)
br label %12
12: ; preds = %10, %2
%13 = tail call i32 @gpio_read(i8* %1, i32 8)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @write(i32 %0, i8* %6, i32 4)
ret void
}