#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 timeval {
  long tv_sec;
  int tv_usec;
  int /*<<< orphan*/ member_0;
};
struct pollfd {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ Gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int poll(struct pollfd *, unsigned int, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
  int n;
  struct timeval tv, tv_orig = {
                         0,
                     };
  struct timeval start, end, delta;
  if (timeout >= 0) {
    tv_orig.tv_sec = (long)timeout / 1000;
    tv_orig.tv_usec = (timeout % 1000) * 1000;
    Gettimeofday(&start, NULL);
  }
  do {
    n = poll(ufds, nfds, timeout);
    if (n < 0 && errno != EINTR)
      do {
        fprintf(stderr, "ERROR: [%s:%d] %s: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/ystk/debian-freeipmi/refs/"
                "heads/master/ipmipower/src/wrappers.c",
                499, "poll", strerror(errno));
      } while (0);
    if (n < 0 && timeout >= 0) {
      Gettimeofday(&end, NULL);
      do {
        (&delta)->tv_sec = (&end)->tv_sec - (&start)->tv_sec;
        (&delta)->tv_usec = (&end)->tv_usec - (&start)->tv_usec;
        if ((&delta)->tv_usec < 0) {
          --(&delta)->tv_sec;
          (&delta)->tv_usec += 1000000;
        }
      } while (0);
      do {
        (&tv)->tv_sec = (&tv_orig)->tv_sec - (&delta)->tv_sec;
        (&tv)->tv_usec = (&tv_orig)->tv_usec - (&delta)->tv_usec;
        if ((&tv)->tv_usec < 0) {
          --(&tv)->tv_sec;
          (&tv)->tv_usec += 1000000;
        }
      } while (0);
      timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    }
  } while (n < 0);
  return n;
}


x86 assembly (clang, -O0):
<Poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
cmpl   $0x0,-0x10(%rbp)
jl     11b2 <Poll+0x62>
movslq -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x30(%rbp)
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <Gettimeofday@plt>
jmp    11b7 <Poll+0x67>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1237 <Poll+0xe7>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
je     1237 <Poll+0xe7>
jmp    11f2 <Poll+0xa2>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%r9
lea    0xde6(%rip),%rsi
lea    0xdf6(%rip),%rdx
mov    $0x1f3,%ecx
lea    0xe84(%rip),%r8
call   1040 <fprintf@plt>
jmp    1237 <Poll+0xe7>
cmpl   $0x0,-0x14(%rbp)
jge    12f9 <Poll+0x1a9>
cmpl   $0x0,-0x10(%rbp)
jl     12f9 <Poll+0x1a9>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <Gettimeofday@plt>
mov    -0x58(%rbp),%rax
sub    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jge    128e <Poll+0x13e>
mov    -0x68(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x60(%rbp)
jmp    1293 <Poll+0x143>
jmp    1298 <Poll+0x148>
mov    -0x38(%rbp),%rax
sub    -0x68(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x60(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12ce <Poll+0x17e>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x20(%rbp)
jmp    12d3 <Poll+0x183>
imul   $0x3e8,-0x28(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    12fe <Poll+0x1ae>
cmpl   $0x0,-0x14(%rbp)
jl     11b7 <Poll+0x67>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Poll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
test   %edx,%edx
js     118e <Poll+0x4e>
mov    %ebp,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %rax,0x10(%rsp)
imul   $0x3e8,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
imul   $0x3e8,%ecx,%eax
mov    %eax,0xc(%rsp)
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1040 <Gettimeofday@plt>
jmp    119d <Poll+0x5d>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <poll@plt>
test   %eax,%eax
js     11bd <Poll+0x7d>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e14(%rip),%rbx
mov    0x2e05(%rip),%r12
jmp    11e1 <Poll+0xa1>
nopl   (%rax)
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <poll@plt>
test   %eax,%eax
jns    11ae <Poll+0x6e>
mov    (%rbx),%rdi
cmp    (%r12),%rdi
je     121e <Poll+0xde>
mov    0x2def(%rip),%rax
mov    (%rax),%r13d
call   1060 <strerror@plt>
mov    %r13d,%edi
lea    0xdfd(%rip),%rsi
lea    0xe0d(%rip),%rdx
mov    $0x1f3,%ecx
lea    0xe9b(%rip),%r8
mov    %rax,%r9
call   1030 <fprintf@plt>
test   %ebp,%ebp
js     11d0 <Poll+0x90>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <Gettimeofday@plt>
mov    0x20(%rsp),%eax
sub    0x30(%rsp),%eax
lea    0xf4240(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x1f,%eax
mov    0x28(%rsp),%edx
add    0x18(%rsp),%eax
add    0x10(%rsp),%edx
sub    %eax,%edx
mov    0xc(%rsp),%eax
sub    %ecx,%eax
lea    0xf4240(%rax),%ecx
mov    %eax,%esi
sar    $0x1f,%esi
test   %eax,%eax
cmovns %eax,%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
add    %edx,%esi
imul   $0x3e8,%esi,%ebp
add    %eax,%ebp
jmp    11d0 <Poll+0x90>

LLVM IR (-O0):
%struct.pollfd = type { i32 }
%struct.timeval = type { i64, i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: [%s:%d] %s: %s\0A\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ystk/debian-freeipmi/refs/heads/master/ipmipower/src/wrappers.c\00"
@.str.2 = [5 x i8] c"poll\00"
define i32 @Poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.pollfd*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
store %struct.pollfd* %0, %struct.pollfd** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = bitcast %struct.timeval* %9 to i8*
%14 = load i32, i32* %6
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = sdiv i64 %18, 1000
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i64 %19, i64* %20
%21 = load i32, i32* %6
%22 = srem i32 %21, 1000
%23 = mul nsw i32 %22, 1000
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i32 %23, i32* %24
%25 = call i32 @Gettimeofday(%struct.timeval* %10, i32* null)
br label %26
26: ; preds = %16, %3
br label %27
27: ; preds = %113, %26
%28 = load %struct.pollfd*, %struct.pollfd** %4
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @poll(%struct.pollfd* %28, i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %27
%35 = load i64, i64* @errno
%36 = load i64, i64* @EINTR
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34
br label %39
39: ; preds = %38
%40 = load i32, i32* @stderr
%41 = load i64, i64* @errno
%42 = call i8* @strerror(i64 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 499, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39
br label %45
45: ; preds = %44, %34, %27
%46 = load i32, i32* %7
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %112
48: ; preds = %45
%49 = load i32, i32* %6
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %112
51: ; preds = %48
%52 = call i32 @Gettimeofday(%struct.timeval* %11, i32* null)
br label %53
53: ; preds = %51
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%55 = load i64, i64* %54
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%57 = load i64, i64* %56
%58 = sub nsw i64 %55, %57
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i64 %58, i64* %59
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%63 = load i32, i32* %62
%64 = sub nsw i32 %61, %63
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i32 %64, i32* %65
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%67 = load i32, i32* %66
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %53
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%71 = load i64, i64* %70
%72 = add nsw i64 %71, -1
store i64 %72, i64* %70
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1000000
store i32 %75, i32* %73
br label %76
76: ; preds = %69, %53
br label %77
77: ; preds = %76
br label %78
78: ; preds = %77
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%80 = load i64, i64* %79
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%82 = load i64, i64* %81
%83 = sub nsw i64 %80, %82
%84 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i64 %83, i64* %84
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%86 = load i32, i32* %85
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%88 = load i32, i32* %87
%89 = sub nsw i32 %86, %88
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i32 %89, i32* %90
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%92 = load i32, i32* %91
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %78
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%96 = load i64, i64* %95
%97 = add nsw i64 %96, -1
store i64 %97, i64* %95
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%99 = load i32, i32* %98
%100 = add nsw i32 %99, 1000000
store i32 %100, i32* %98
br label %101
101: ; preds = %94, %78
br label %102
102: ; preds = %101
%103 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%104 = load i64, i64* %103
%105 = mul nsw i64 %104, 1000
%106 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%107 = load i32, i32* %106
%108 = sdiv i32 %107, 1000
%109 = sext i32 %108 to i64
%110 = add nsw i64 %105, %109
%111 = trunc i64 %110 to i32
store i32 %111, i32* %6
br label %112
112: ; preds = %102, %48, %45
br label %113
113: ; preds = %112
%114 = load i32, i32* %7
%115 = icmp slt i32 %114, 0
br i1 %115, label %27, label %116
116: ; preds = %113
%117 = load i32, i32* %7
ret i32 %117
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
%struct.timeval = type { i64, i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: [%s:%d] %s: %s\0A\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ystk/debian-freeipmi/refs/heads/master/ipmipower/src/wrappers.c\00"
@.str.2 = [5 x i8] c"poll\00"
define i32 @Poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
%8 = icmp sgt i32 %2, -1
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = udiv i32 %2, 1000
%11 = zext i32 %10 to i64
%12 = urem i32 %2, 1000
%13 = mul nuw nsw i32 %12, 1000
%14 = call i32 @Gettimeofday(%struct.timeval* %4, i32* null)
br label %15
15: ; preds = %9, %3
%16 = phi i64 [ %11, %9 ], [ 0, %3 ]
%17 = phi i32 [ %13, %9 ], [ 0, %3 ]
%18 = call i32 @poll(%struct.pollfd* %0, i32 %1, i32 %2)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %65
20: ; preds = %15
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
br label %25
25: ; preds = %20, %61
%26 = phi i32 [ %2, %20 ], [ %62, %61 ]
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp eq i64 %27, %28
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i8* @strerror(i64 %27)
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 499, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %25
%35 = icmp sgt i32 %26, -1
br i1 %35, label %36, label %61
36: ; preds = %34
%37 = call i32 @Gettimeofday(%struct.timeval* %5, i32* null)
%38 = load i64, i64* %21
%39 = load i64, i64* %22
%40 = load i32, i32* %23
%41 = load i32, i32* %24
%42 = sub nsw i32 %40, %41
%43 = icmp slt i32 %42, 0
%44 = add nsw i32 %42, 1000000
%45 = select i1 %43, i32 %44, i32 %42
%46 = ashr i32 %42, 31
%47 = zext i32 %46 to i64
%48 = add i64 %16, %39
%49 = add i64 %38, %47
%50 = sub i64 %48, %49
%51 = sub nsw i32 %17, %45
%52 = icmp slt i32 %51, 0
%53 = add nsw i32 %51, 1000000
%54 = ashr i32 %51, 31
%55 = select i1 %52, i32 %53, i32 %51
%56 = sdiv i32 %55, 1000
%57 = trunc i64 %50 to i32
%58 = add i32 %54, %57
%59 = mul i32 %58, 1000
%60 = add i32 %59, %56
br label %61
61: ; preds = %34, %36
%62 = phi i32 [ %60, %36 ], [ %26, %34 ]
%63 = call i32 @poll(%struct.pollfd* %0, i32 %1, i32 %62)
%64 = icmp slt i32 %63, 0
br i1 %64, label %25, label %65
65: ; preds = %61, %15
%66 = phi i32 [ %18, %15 ], [ %63, %61 ]
ret i32 %66
}