#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 */
struct pollfd {
  int fd;
  scalar_t__ revents;
};
typedef int /*<<< orphan*/ fdset;

/* Variables and functions */
int /*<<< orphan*/ gpio_close(int);
int gpio_open_isr(int);
int gpio_read_isr(struct pollfd *, char *, int);
int /*<<< orphan*/ memset(struct pollfd *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void test_gpio_interrupt(void) {
  int ret = 0;
  char buf[255] = {
      0,
  };
  int isr_fd;
  struct pollfd fdset;
  int len;
  int poll_state;
  int status;
  int i = 0;
  memset(&fdset, 0, sizeof(fdset));
  printf("test_gpio_intterupt start\n");
  isr_fd = gpio_open_isr(134);
  printf("isr_fd[%d]\n", isr_fd);
  fdset.fd = isr_fd;
  fdset.revents = 0;
  while (1) {
    status = gpio_read_isr(&fdset, buf, 1);
    if (status > 0) {
      printf("app[%s]\n", buf);
    }
  }
  gpio_close(134);
  gpio_close(135);
}


x86 assembly (clang, -O0):
<test_gpio_interrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1060 <memset@plt>
movl   $0x0,-0x138(%rbp)
lea    -0x128(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x86,%edi
call   1050 <gpio_open_isr@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x114(%rbp),%eax
mov    %eax,-0x128(%rbp)
movq   $0x0,-0x120(%rbp)
lea    -0x110(%rbp),%rsi
lea    -0x128(%rbp),%rdi
mov    $0x1,%edx
call   1030 <gpio_read_isr@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jle    120b <test_gpio_interrupt+0xcb>
lea    -0x110(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cb <test_gpio_interrupt+0x8b>

x86 assembly (clang, -O2):
<test_gpio_interrupt>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xff(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    $0x86,%edi
call   1060 <gpio_open_isr@plt>
mov    %eax,%ebx
lea    0xe05(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rbx
lea    0xdf0(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <gpio_read_isr@plt>
test   %eax,%eax
jle    1220 <test_gpio_interrupt+0xd0>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1220 <test_gpio_interrupt+0xd0>

LLVM IR (-O0):
%struct.pollfd = type { i32, i64 }
@.str = [27 x i8] c"test_gpio_intterupt start\0A\00"
@.str.1 = [12 x i8] c"isr_fd[%d]\0A\00"
@.str.2 = [9 x i8] c"app[%s]\0A\00"
define void @test_gpio_interrupt() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = alloca %struct.pollfd
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [255 x i8]* %2 to i8*
store i32 0, i32* %8
%10 = call i32 @memset(%struct.pollfd* %4, i32 0, i32 16)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @gpio_open_isr(i32 134)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i64 0, i64* %17
br label %18
18: ; preds = %0, %26
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%20 = call i32 @gpio_read_isr(%struct.pollfd* %4, i8* %19, i32 1)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %18
br label %18
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64 }
@.str.1 = [12 x i8] c"isr_fd[%d]\0A\00"
@.str.2 = [9 x i8] c"app[%s]\0A\00"
@str = [26 x i8] c"test_gpio_intterupt start\00"
define void @test_gpio_interrupt() {
%1 = alloca [255 x i8]
%2 = alloca %struct.pollfd
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.pollfd* %2 to i8*
%5 = call i32 @memset(%struct.pollfd* %2, i32 0, i32 16)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%7 = call i32 @gpio_open_isr(i32 134)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %7, i32* %9
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i64 0, i64* %10
br label %11
11: ; preds = %16, %0
%12 = call i32 @gpio_read_isr(%struct.pollfd* %2, i8* %3, i32 1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %14, %11
br label %11
}