#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int pin_get_level(int fd, struct pollfd *fds) {
  int res;
  int rc;
  char buf[3];
  rc = poll(fds, 1, 100000);
  if (rc < 0) {
    fprintf(stderr, "Error on poll!\n");
    return -1;
  }
  lseek(fd, 0, SEEK_SET);
  read(fd, buf, 3);
  buf[1] = 0;
  res = atoi(buf);
  return res;
}


x86 assembly (clang, -O0):
<pin_get_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1060 <poll@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a0 <pin_get_level+0x50>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <pin_get_level+0x8a>
mov    -0x8(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x1b(%rbp),%rsi
mov    $0x3,%edx
call   1040 <read@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x1b(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pin_get_level>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsi,%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1060 <poll@plt>
test   %eax,%eax
js     11a1 <pin_get_level+0x51>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
lea    0x5(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <read@plt>
movb   $0x0,0x6(%rsp)
mov    %r14,%rdi
call   1070 <atoi@plt>
jmp    11bb <pin_get_level+0x6b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pollfd = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Error on poll!\0A\00"
@SEEK_SET = global i32 0
define i32 @pin_get_level(i32 %0, %struct.pollfd* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.pollfd*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i8]
store i32 %0, i32* %4
store %struct.pollfd* %1, %struct.pollfd** %5
%9 = load %struct.pollfd*, %struct.pollfd** %5
%10 = call i32 @poll(%struct.pollfd* %9, i32 1, i32 100000)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @lseek(i32 %17, i32 0, i32 %18)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 3)
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 0, i8* %23
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %27
27: ; preds = %16, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Error on poll!\0A\00"
@SEEK_SET = global i32 0
define i32 @pin_get_level(i32 %0, %struct.pollfd* %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @poll(%struct.pollfd* %1, i32 1, i32 100000)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %2
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %0, i32 0, i32 %11)
%13 = call i32 @read(i32 %0, i8* %4, i32 3)
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 0, i8* %14
%15 = call i32 @atoi(i8* %4)
br label %16
16: ; preds = %10, %7
%17 = phi i32 [ -1, %7 ], [ %15, %10 ]
ret i32 %17
}