#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;
  int events;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int POLLERR;
int POLLPRI;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int fd;
  struct pollfd fds;
  printf("Inicio do programa\n");
  fd = open("/sys/class/gpio/gpio139/value", O_RDONLY);
  fds.fd = fd;
  fds.events = POLLPRI | POLLERR;
  poll(&fds, 1, -1);
  printf("Fim do programa\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xec0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    0x2e6e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <poll@plt>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0xeb3(%rip),%rdi
call   1050 <open@plt>
mov    %eax,(%rsp)
mov    0x2e94(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <poll@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@.str = [20 x i8] c"Inicio do programa\0A\00"
@.str.1 = [30 x i8] c"/sys/class/gpio/gpio139/value\00"
@O_RDONLY = global i32 0
@POLLPRI = global i32 0
@POLLERR = global i32 0
@.str.2 = [17 x i8] c"Fim do programa\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.pollfd
%3 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @POLLPRI
%9 = load i32, i32* @POLLERR
%10 = or i32 %8, %9
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 -1)
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@.str.1 = [30 x i8] c"/sys/class/gpio/gpio139/value\00"
@O_RDONLY = global i32 0
@POLLPRI = global i32 0
@POLLERR = global i32 0
@str = [19 x i8] c"Inicio do programa\00"
@str.3 = [16 x i8] c"Fim do programa\00"
define i32 @main() {
%1 = alloca %struct.pollfd
%2 = bitcast %struct.pollfd* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @POLLPRI
%8 = load i32, i32* @POLLERR
%9 = or i32 %8, %7
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 1
store i32 %9, i32* %10
%11 = call i32 @poll(%struct.pollfd* %1, i32 1, i32 -1)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}