#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ Gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ _clear_sets(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int Select(int maxfd, fd_set *rset, fd_set *wset, fd_set *eset,
           struct timeval *tv) {
  int n;
  struct timeval tv_orig = {
      0,
  };
  struct timeval start, end, delta;
  if (tv) {
    tv_orig = *tv;
    Gettimeofday(&start, NULL);
  }
  do {
    n = select(maxfd, rset, wset, eset, tv);
    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",
                250, "select", strerror(errno));
      } while (0);
    if (n < 0 && tv != NULL) {
      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);
    }
  } while (n < 0);
  if (n == 0)
    _clear_sets(rset, wset, eset);
  return n;
}


x86 assembly (clang, -O0):
<Select>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x28(%rbp)
je     11c1 <Select+0x61>
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x48(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x40(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <Gettimeofday@plt>
jmp    11c6 <Select+0x66>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1070 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1255 <Select+0xf5>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%rax
je     1255 <Select+0xf5>
jmp    120a <Select+0xaa>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%r9
lea    0xdc8(%rip),%rsi
lea    0xdd8(%rip),%rdx
mov    $0xfa,%ecx
lea    0xe66(%rip),%r8
call   1050 <fprintf@plt>
jmp    1255 <Select+0xf5>
cmpl   $0x0,-0x2c(%rbp)
jge    1331 <Select+0x1d1>
cmpq   $0x0,-0x28(%rbp)
je     1331 <Select+0x1d1>
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <Gettimeofday@plt>
mov    -0x70(%rbp),%rax
sub    -0x58(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rax
sub    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jge    12c9 <Select+0x169>
mov    -0x88(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x88(%rbp)
mov    -0x90(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x90(%rbp)
jmp    12ce <Select+0x16e>
jmp    12d3 <Select+0x173>
mov    -0x40(%rbp),%rcx
sub    -0x88(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x48(%rbp),%rcx
sub    -0x90(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1327 <Select+0x1c7>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
jmp    132c <Select+0x1cc>
jmp    1331 <Select+0x1d1>
jmp    1336 <Select+0x1d6>
cmpl   $0x0,-0x2c(%rbp)
jl     11c6 <Select+0x66>
cmpl   $0x0,-0x2c(%rbp)
jne    135b <Select+0x1fb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <_clear_sets@plt>
mov    -0x2c(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Select>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r15
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%r14d
test   %r8,%r8
je     1191 <Select+0x41>
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    0x8(%r15),%rax
mov    %rax,0x10(%rsp)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <Gettimeofday@plt>
jmp    119f <Select+0x4f>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r15,%r8
call   1060 <select@plt>
mov    %eax,%r13d
test   %eax,%eax
js     11fc <Select+0xac>
test   %r13d,%r13d
je     12ca <Select+0x17a>
mov    %r13d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r15,%r8
call   1060 <select@plt>
test   %eax,%eax
jns    12be <Select+0x16e>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rdi
mov    0x2dc3(%rip),%rax
cmp    (%rax),%rdi
je     1250 <Select+0x100>
mov    %rbx,%r13
mov    %rbp,%rbx
mov    0x2dc1(%rip),%rax
mov    (%rax),%ebp
call   1070 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rbp
mov    %r13,%rbx
lea    0xdcb(%rip),%rsi
lea    0xddb(%rip),%rdx
mov    $0xfa,%ecx
lea    0xe69(%rip),%r8
mov    %rax,%r9
call   1040 <fprintf@plt>
test   %r15,%r15
je     11e0 <Select+0x90>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <Gettimeofday@plt>
mov    0x18(%rsp),%rax
sub    0x30(%rsp),%rax
lea    0xf4240(%rax),%rdx
mov    %rax,%rcx
shr    $0x3f,%rcx
test   %rax,%rax
cmovns %rax,%rdx
mov    0x10(%rsp),%rax
sub    0x20(%rsp),%rax
add    0x38(%rsp),%rax
add    %rcx,%rax
mov    %rax,0x8(%r15)
mov    0x8(%rsp),%rcx
sub    %rdx,%rcx
mov    %rcx,(%r15)
jns    11e0 <Select+0x90>
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%r15)
add    $0xf4240,%rcx
mov    %rcx,(%r15)
jmp    11e0 <Select+0x90>
mov    %eax,%r13d
test   %r13d,%r13d
jne    11c3 <Select+0x73>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <_clear_sets@plt>
jmp    11c3 <Select+0x73>

LLVM IR (-O0):
%struct.timeval = type { i64, i64, 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 = [7 x i8] c"select\00"
define i32 @Select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.timeval*
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store %struct.timeval* %4, %struct.timeval** %10
%16 = bitcast %struct.timeval* %12 to i8*
%17 = load %struct.timeval*, %struct.timeval** %10
%18 = icmp ne %struct.timeval* %17, null
br i1 %18, label %19, label %24
19: ; preds = %5
%20 = load %struct.timeval*, %struct.timeval** %10
%21 = bitcast %struct.timeval* %12 to i8*
%22 = bitcast %struct.timeval* %20 to i8*
%23 = call i32 @Gettimeofday(%struct.timeval* %13, i32* null)
br label %24
24: ; preds = %19, %5
br label %25
25: ; preds = %109, %24
%26 = load i32, i32* %6
%27 = load i32*, i32** %7
%28 = load i32*, i32** %8
%29 = load i32*, i32** %9
%30 = load %struct.timeval*, %struct.timeval** %10
%31 = call i32 @select(i32 %26, i32* %27, i32* %28, i32* %29, %struct.timeval* %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %25
%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 250, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39
br label %45
45: ; preds = %44, %34, %25
%46 = load i32, i32* %11
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %108
48: ; preds = %45
%49 = load %struct.timeval*, %struct.timeval** %10
%50 = icmp ne %struct.timeval* %49, null
br i1 %50, label %51, label %108
51: ; preds = %48
%52 = call i32 @Gettimeofday(%struct.timeval* %14, i32* null)
br label %53
53: ; preds = %51
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%55 = load i64, i64* %54
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%57 = load i64, i64* %56
%58 = sub nsw i64 %55, %57
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i64 %58, i64* %59
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%61 = load i64, i64* %60
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%63 = load i64, i64* %62
%64 = sub nsw i64 %61, %63
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i64 %64, i64* %65
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%67 = load i64, i64* %66
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %53
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%71 = load i64, i64* %70
%72 = add nsw i64 %71, -1
store i64 %72, i64* %70
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%74 = load i64, i64* %73
%75 = add nsw i64 %74, 1000000
store i64 %75, i64* %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* %12, i32 0, i32 1
%80 = load i64, i64* %79
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%82 = load i64, i64* %81
%83 = sub nsw i64 %80, %82
%84 = load %struct.timeval*, %struct.timeval** %10
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %84, i32 0, i32 1
store i64 %83, i64* %85
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%87 = load i64, i64* %86
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%89 = load i64, i64* %88
%90 = sub nsw i64 %87, %89
%91 = load %struct.timeval*, %struct.timeval** %10
%92 = getelementptr inbounds %struct.timeval, %struct.timeval* %91, i32 0, i32 0
store i64 %90, i64* %92
%93 = load %struct.timeval*, %struct.timeval** %10
%94 = getelementptr inbounds %struct.timeval, %struct.timeval* %93, i32 0, i32 0
%95 = load i64, i64* %94
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %106
97: ; preds = %78
%98 = load %struct.timeval*, %struct.timeval** %10
%99 = getelementptr inbounds %struct.timeval, %struct.timeval* %98, i32 0, i32 1
%100 = load i64, i64* %99
%101 = add nsw i64 %100, -1
store i64 %101, i64* %99
%102 = load %struct.timeval*, %struct.timeval** %10
%103 = getelementptr inbounds %struct.timeval, %struct.timeval* %102, i32 0, i32 0
%104 = load i64, i64* %103
%105 = add nsw i64 %104, 1000000
store i64 %105, i64* %103
br label %106
106: ; preds = %97, %78
br label %107
107: ; preds = %106
br label %108
108: ; preds = %107, %48, %45
br label %109
109: ; preds = %108
%110 = load i32, i32* %11
%111 = icmp slt i32 %110, 0
br i1 %111, label %25, label %112
112: ; preds = %109
%113 = load i32, i32* %11
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %112
%116 = load i32*, i32** %7
%117 = load i32*, i32** %8
%118 = load i32*, i32** %9
%119 = call i32 @_clear_sets(i32* %116, i32* %117, i32* %118)
br label %120
120: ; preds = %115, %112
%121 = load i32, i32* %11
ret i32 %121
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64, 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 = [7 x i8] c"select\00"
define i32 @Select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast %struct.timeval* %6 to i8*
%9 = bitcast %struct.timeval* %7 to i8*
%10 = icmp eq %struct.timeval* %4, null
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%15 = load i64, i64* %14
%16 = call i32 @Gettimeofday(%struct.timeval* %6, i32* null)
br label %17
17: ; preds = %11, %5
%18 = phi i64 [ %15, %11 ], [ 0, %5 ]
%19 = phi i64 [ %13, %11 ], [ 0, %5 ]
%20 = call i32 @select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %60
22: ; preds = %17
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
br label %29
29: ; preds = %22, %57
%30 = load i64, i64* @errno
%31 = load i64, i64* @EINTR
%32 = icmp eq i64 %30, %31
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i8* @strerror(i64 %30)
%36 = call i32 @fprintf(i32 %34, 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 250, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %33, %29
br i1 %10, label %57, label %38
38: ; preds = %37
%39 = call i32 @Gettimeofday(%struct.timeval* %7, i32* null)
%40 = load i64, i64* %23
%41 = load i64, i64* %24
%42 = load i64, i64* %25
%43 = load i64, i64* %26
%44 = sub nsw i64 %42, %43
%45 = icmp slt i64 %44, 0
%46 = add nsw i64 %44, 1000000
%47 = lshr i64 %44, 63
%48 = select i1 %45, i64 %46, i64 %44
%49 = sub i64 %18, %40
%50 = add i64 %49, %41
%51 = add i64 %50, %47
store i64 %51, i64* %27
%52 = sub nsw i64 %19, %48
store i64 %52, i64* %28
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %38
%55 = add nsw i64 %51, -1
store i64 %55, i64* %27
%56 = add nsw i64 %52, 1000000
store i64 %56, i64* %28
br label %57
57: ; preds = %37, %54, %38
%58 = call i32 @select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4)
%59 = icmp slt i32 %58, 0
br i1 %59, label %29, label %60
60: ; preds = %57, %17
%61 = phi i32 [ %20, %17 ], [ %58, %57 ]
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @_clear_sets(i32* %1, i32* %2, i32* %3)
br label %65
65: ; preds = %63, %60
ret i32 %61
}