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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ compare_timevals(struct timeval *, struct timeval *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ get_response(int, short);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ init(char *, struct sockaddr_in *, int *);
int random();
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ send_fail_message_to_wcm();
int /*<<< orphan*/ send_ping(int, struct sockaddr_in, short, short);
int /*<<< orphan*/ send_success_message_to_wcm();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ subtract_timevals(struct timeval *, struct timeval *,
                                     struct timeval *);
int main() {
  char *addr = "10.19.173.30";
  int poll_interval = 15;
  int wait_interval = 3;
  int max_attempts = 5;
  struct sockaddr_in dest;
  int sock;
  short sequence;
  init(addr, &dest, &sock);
  sequence = 1;
  while (1) {
    struct timeval tv, now, expire;
    int attempt = 0;
    short identifier = random() & 0x7fff;
    int response = 0;
    fd_set rfds;
    do {
      send_ping(sock, dest, identifier, sequence);
      sequence++;
      if (sequence < 0)
        sequence = 1;
      attempt++;
      gettimeofday(&now, NULL);
      expire = now;
      expire.tv_sec += wait_interval;
      do {
        subtract_timevals(&tv, &expire, &now);
        FD_ZERO(&rfds);
        FD_SET(sock, &rfds);
        fprintf(stderr, "INFO: select for %d.%06d\n", tv.tv_sec, tv.tv_usec);
        if (tv.tv_sec >= 0)
          if (select(sock + 1, &rfds, NULL, NULL, &tv) > 0) {
            fprintf(stderr, "INFO: select awoke!\n");
            if (get_response(sock, identifier)) {
              fprintf(stderr, "INFO: got expected response!\n");
              response = 1;
            }
          }
        gettimeofday(&now, NULL);
      } while (!response && compare_timevals(&now, &expire) < 0);
    } while (!response && attempt < max_attempts);
    if (response)
      send_success_message_to_wcm();
    else
      send_fail_message_to_wcm();
    gettimeofday(&now, NULL);
    expire = now;
    expire.tv_sec += poll_interval;
    do {
      subtract_timevals(&tv, &expire, &now);
      FD_ZERO(&rfds);
      FD_SET(sock, &rfds);
      fprintf(stderr, "INFO: sleeping for %d.%06d\n", tv.tv_sec, tv.tv_usec);
      if (tv.tv_sec >= 0)
        if (select(sock + 1, &rfds, NULL, NULL, &tv) > 0)
          get_response(sock, identifier);
      gettimeofday(&now, NULL);
    } while (compare_timevals(&now, &expire) < 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe1a(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0xf,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <init@plt>
movw   $0x1,-0x26(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x0,%al
call   10b0 <random@plt>
and    $0x7fff,%eax
mov    %ax,-0x46(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x46(%rbp),%cx
mov    -0x26(%rbp),%ax
mov    -0x20(%rbp),%esi
movswl %cx,%edx
movswl %ax,%ecx
call   10c0 <send_ping@plt>
mov    -0x26(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x26(%rbp)
movswl -0x26(%rbp),%eax
cmp    $0x0,%eax
jge    126c <main+0x9c>
movw   $0x1,-0x26(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <subtract_timevals@plt>
lea    -0x50(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x30(%rbp)
jl     1359 <main+0x189>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rdx
call   10a0 <select@plt>
cmp    $0x0,%rax
jle    1354 <main+0x184>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%edi
movswl -0x46(%rbp),%esi
call   1050 <get_response@plt>
cmp    $0x0,%rax
je     134f <main+0x17f>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4c(%rbp)
jmp    1354 <main+0x184>
jmp    1359 <main+0x189>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4c(%rbp)
mov    %al,-0x51(%rbp)
jne    138c <main+0x1bc>
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10d0 <compare_timevals@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1293 <main+0xc3>
jmp    139c <main+0x1cc>
xor    %eax,%eax
cmpl   $0x0,-0x4c(%rbp)
mov    %al,-0x52(%rbp)
jne    13b7 <main+0x1e7>
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x52(%rbp)
mov    -0x52(%rbp),%al
test   $0x1,%al
jne    1234 <main+0x64>
cmpl   $0x0,-0x4c(%rbp)
je     13d8 <main+0x208>
mov    $0x0,%al
call   1030 <send_success_message_to_wcm@plt>
jmp    13df <main+0x20f>
mov    $0x0,%al
call   10f0 <send_fail_message_to_wcm@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <subtract_timevals@plt>
lea    -0x50(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xc21(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x30(%rbp)
jl     147f <main+0x2af>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rdx
call   10a0 <select@plt>
cmp    $0x0,%rax
jle    147a <main+0x2aa>
mov    -0x24(%rbp),%edi
movswl -0x46(%rbp),%esi
call   1050 <get_response@plt>
jmp    147f <main+0x2af>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10d0 <compare_timevals@plt>
cmp    $0x0,%rax
jl     13fd <main+0x22d>
jmp    1216 <main+0x46>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe1b(%rip),%rdi
lea    0x20(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1080 <init@plt>
mov    $0x1,%ax
mov    %eax,0x10(%rsp)
lea    0x28(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x34(%rsp),%r13
xor    %eax,%eax
call   10b0 <random@plt>
and    $0x7fff,%eax
mov    %eax,0x24(%rsp)
xor    %r14d,%r14d
jmp    123a <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x5,%r14d
je     141d <main+0x24d>
mov    0x4(%rsp),%edi
mov    0x20(%rsp),%esi
movzwl 0x24(%rsp),%edx
mov    0x10(%rsp),%ebp
movswl %bp,%ebp
mov    %edx,0x14(%rsp)
mov    %ebp,%ecx
call   10c0 <send_ping@plt>
add    $0x1,%ebp
test   %bp,%bp
mov    $0x1,%eax
cmovs  %eax,%ebp
mov    %ebp,0x10(%rsp)
mov    0x2d6e(%rip),%rbp
add    $0x1,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x28(%rsp),%rax
mov    %rax,0x18(%rsp)
add    $0x3,%eax
mov    %eax,0x18(%rsp)
jmp    12be <main+0xee>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <compare_timevals@plt>
test   %rax,%rax
jns    1230 <main+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <subtract_timevals@plt>
mov    %r13,%rdi
call   1090 <FD_ZERO@plt>
mov    0x4(%rsp),%edi
mov    %r13,%rsi
call   10e0 <FD_SET@plt>
mov    0x0(%rbp),%edi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xd1b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpl   $0x0,0x8(%rsp)
js     12a0 <main+0xd0>
mov    0x4(%rsp),%edi
add    $0x1,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10a0 <select@plt>
test   %rax,%rax
jle    12a0 <main+0xd0>
mov    0x0(%rbp),%edi
lea    0xd02(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x4(%rsp),%edi
mov    0x14(%rsp),%esi
call   1050 <get_response@plt>
test   %rax,%rax
je     12a0 <main+0xd0>
mov    0x0(%rbp),%edi
lea    0xcf0(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
xor    %eax,%eax
call   1030 <send_success_message_to_wcm@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x28(%rsp),%rax
mov    %rax,0x18(%rsp)
add    $0xf,%eax
mov    %eax,0x18(%rsp)
jmp    13ae <main+0x1de>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <compare_timevals@plt>
test   %rax,%rax
jns    1210 <main+0x40>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <subtract_timevals@plt>
mov    %r13,%rdi
call   1090 <FD_ZERO@plt>
mov    0x4(%rsp),%edi
mov    %r13,%rsi
call   10e0 <FD_SET@plt>
mov    0x0(%rbp),%edi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xc78(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpl   $0x0,0x8(%rsp)
js     1390 <main+0x1c0>
mov    0x4(%rsp),%edi
add    $0x1,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10a0 <select@plt>
test   %rax,%rax
jle    1390 <main+0x1c0>
mov    0x4(%rsp),%edi
mov    0x14(%rsp),%esi
call   1050 <get_response@plt>
jmp    1390 <main+0x1c0>
xor    %eax,%eax
call   10f0 <send_fail_message_to_wcm@plt>
jmp    1364 <main+0x194>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"10.19.173.30\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"INFO: select for %d.%06d\0A\00"
@.str.2 = [21 x i8] c"INFO: select awoke!\0A\00"
@.str.3 = [30 x i8] c"INFO: got expected response!\0A\00"
@.str.4 = [28 x i8] c"INFO: sleeping for %d.%06d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i16
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i32
%13 = alloca i16
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 15, i32* %3
store i32 3, i32* %4
store i32 5, i32* %5
%16 = load i8*, i8** %2
%17 = call i32 @init(i8* %16, %struct.sockaddr_in* %6, i32* %7)
store i16 1, i16* %8
br label %18
18: ; preds = %0, %140
store i32 0, i32* %12
%19 = call i32 (...) @random()
%20 = and i32 %19, 32767
%21 = trunc i32 %20 to i16
store i16 %21, i16* %13
store i32 0, i32* %14
br label %22
22: ; preds = %94, %18
%23 = load i32, i32* %7
%24 = load i16, i16* %13
%25 = load i16, i16* %8
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @send_ping(i32 %23, i32 %27, i16 signext %24, i16 signext %25)
%29 = load i16, i16* %8
%30 = add i16 %29, 1
store i16 %30, i16* %8
%31 = load i16, i16* %8
%32 = sext i16 %31 to i32
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %22
store i16 1, i16* %8
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
%38 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%39 = bitcast %struct.timeval* %11 to i8*
%40 = bitcast %struct.timeval* %10 to i8*
%41 = load i32, i32* %4
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%43 = load i32, i32* %42
%44 = add nsw i32 %43, %41
store i32 %44, i32* %42
br label %45
45: ; preds = %84, %35
%46 = call i32 @subtract_timevals(%struct.timeval* %9, %struct.timeval* %11, %struct.timeval* %10)
%47 = call i32 @FD_ZERO(i32* %15)
%48 = load i32, i32* %7
%49 = call i32 @FD_SET(i32 %48, i32* %15)
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%54 = load i32, i32* %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %54)
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%57 = load i32, i32* %56
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %45
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
%62 = call i64 @select(i32 %61, i32* %15, i32* null, i32* null, %struct.timeval* %9)
%63 = icmp sgt i64 %62, 0
br i1 %63, label %64, label %75
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%67 = load i32, i32* %7
%68 = load i16, i16* %13
%69 = call i64 @get_response(i32 %67, i16 signext %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %14
br label %74
74: ; preds = %71, %64
br label %75
75: ; preds = %74, %59
br label %76
76: ; preds = %75, %45
%77 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
br label %78
78: ; preds = %76
%79 = load i32, i32* %14
%80 = icmp ne i32 %79, 0
br i1 %80, label %84, label %81
81: ; preds = %78
%82 = call i64 @compare_timevals(%struct.timeval* %10, %struct.timeval* %11)
%83 = icmp slt i64 %82, 0
br label %84
84: ; preds = %81, %78
%85 = phi i1 [ false, %78 ], [ %83, %81 ]
br i1 %85, label %45, label %86
86: ; preds = %84
br label %87
87: ; preds = %86
%88 = load i32, i32* %14
%89 = icmp ne i32 %88, 0
br i1 %89, label %94, label %90
90: ; preds = %87
%91 = load i32, i32* %12
%92 = load i32, i32* %5
%93 = icmp slt i32 %91, %92
br label %94
94: ; preds = %90, %87
%95 = phi i1 [ false, %87 ], [ %93, %90 ]
br i1 %95, label %22, label %96
96: ; preds = %94
%97 = load i32, i32* %14
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = call i32 (...) @send_success_message_to_wcm()
br label %103
101: ; preds = %96
%102 = call i32 (...) @send_fail_message_to_wcm()
br label %103
103: ; preds = %101, %99
%104 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%105 = bitcast %struct.timeval* %11 to i8*
%106 = bitcast %struct.timeval* %10 to i8*
%107 = load i32, i32* %3
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%109 = load i32, i32* %108
%110 = add nsw i32 %109, %107
store i32 %110, i32* %108
br label %111
111: ; preds = %137, %103
%112 = call i32 @subtract_timevals(%struct.timeval* %9, %struct.timeval* %11, %struct.timeval* %10)
%113 = call i32 @FD_ZERO(i32* %15)
%114 = load i32, i32* %7
%115 = call i32 @FD_SET(i32 %114, i32* %15)
%116 = load i32, i32* @stderr
%117 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%118 = load i32, i32* %117
%119 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%120 = load i32, i32* %119
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %118, i32 %120)
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%123 = load i32, i32* %122
%124 = icmp sge i32 %123, 0
br i1 %124, label %125, label %135
125: ; preds = %111
%126 = load i32, i32* %7
%127 = add nsw i32 %126, 1
%128 = call i64 @select(i32 %127, i32* %15, i32* null, i32* null, %struct.timeval* %9)
%129 = icmp sgt i64 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %125
%131 = load i32, i32* %7
%132 = load i16, i16* %13
%133 = call i64 @get_response(i32 %131, i16 signext %132)
br label %134
134: ; preds = %130, %125
br label %135
135: ; preds = %134, %111
%136 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
br label %137
137: ; preds = %135
%138 = call i64 @compare_timevals(%struct.timeval* %10, %struct.timeval* %11)
%139 = icmp slt i64 %138, 0
br i1 %139, label %111, label %140
140: ; preds = %137
br label %18
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"10.19.173.30\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"INFO: select for %d.%06d\0A\00"
@.str.2 = [21 x i8] c"INFO: select awoke!\0A\00"
@.str.3 = [30 x i8] c"INFO: got expected response!\0A\00"
@.str.4 = [28 x i8] c"INFO: sleeping for %d.%06d\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timeval*
%6 = alloca i64
%7 = bitcast i64* %6 to %struct.timeval*
%8 = alloca i32
%9 = bitcast %struct.sockaddr_in* %1 to i8*
%10 = bitcast i32* %2 to i8*
%11 = call i32 @init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.sockaddr_in* %1, i32* %2)
%12 = bitcast %struct.timeval* %3 to i8*
%13 = bitcast i64* %4 to i8*
%14 = bitcast i64* %6 to i8*
%15 = bitcast i32* %8 to i8*
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%17 = bitcast i64* %6 to i32*
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %20
20: ; preds = %102, %0
%21 = phi i16 [ 1, %0 ], [ %33, %102 ]
%22 = call i32 (...) @random()
%23 = trunc i32 %22 to i16
%24 = and i16 %23, 32767
br label %25
25: ; preds = %70, %20
%26 = phi i32 [ 0, %20 ], [ %34, %70 ]
%27 = phi i16 [ %21, %20 ], [ %33, %70 ]
%28 = load i32, i32* %2
%29 = load i32, i32* %16
%30 = call i32 @send_ping(i32 %28, i32 %29, i16 signext %24, i16 signext %27)
%31 = add i16 %27, 1
%32 = icmp slt i16 %31, 0
%33 = select i1 %32, i16 1, i16 %31
%34 = add nuw nsw i32 %26, 1
%35 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%36 = load i64, i64* %4
store i64 %36, i64* %6
%37 = trunc i64 %36 to i32
%38 = add nsw i32 %37, 3
store i32 %38, i32* %17
br label %39
39: ; preds = %66, %25
%40 = call i32 @subtract_timevals(%struct.timeval* %3, %struct.timeval* %7, %struct.timeval* %5)
%41 = call i32 @FD_ZERO(i32* %8)
%42 = load i32, i32* %2
%43 = call i32 @FD_SET(i32 %42, i32* %8)
%44 = load i32, i32* @stderr
%45 = load i32, i32* %18
%46 = load i32, i32* %19
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32, i32* %18
%49 = icmp sgt i32 %48, -1
br i1 %49, label %50, label %66
50: ; preds = %39
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
%53 = call i64 @select(i32 %52, i32* %8, i32* null, i32* null, %struct.timeval* %3)
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* %2
%59 = call i64 @get_response(i32 %58, i16 signext %24)
%60 = icmp eq i64 %59, 0
br i1 %60, label %66, label %61
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%64 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%65 = call i32 (...) @send_success_message_to_wcm()
br label %74
66: ; preds = %55, %50, %39
%67 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%68 = call i64 @compare_timevals(%struct.timeval* %5, %struct.timeval* %7)
%69 = icmp slt i64 %68, 0
br i1 %69, label %39, label %70
70: ; preds = %66
%71 = icmp eq i32 %34, 5
br i1 %71, label %72, label %25
72: ; preds = %70
%73 = call i32 (...) @send_fail_message_to_wcm()
br label %74
74: ; preds = %72, %61
%75 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%76 = load i64, i64* %4
store i64 %76, i64* %6
%77 = trunc i64 %76 to i32
%78 = add nsw i32 %77, 15
store i32 %78, i32* %17
br label %79
79: ; preds = %98, %74
%80 = call i32 @subtract_timevals(%struct.timeval* %3, %struct.timeval* %7, %struct.timeval* %5)
%81 = call i32 @FD_ZERO(i32* %8)
%82 = load i32, i32* %2
%83 = call i32 @FD_SET(i32 %82, i32* %8)
%84 = load i32, i32* @stderr
%85 = load i32, i32* %18
%86 = load i32, i32* %19
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %85, i32 %86)
%88 = load i32, i32* %18
%89 = icmp sgt i32 %88, -1
br i1 %89, label %90, label %98
90: ; preds = %79
%91 = load i32, i32* %2
%92 = add nsw i32 %91, 1
%93 = call i64 @select(i32 %92, i32* %8, i32* null, i32* null, %struct.timeval* %3)
%94 = icmp sgt i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %90
%96 = load i32, i32* %2
%97 = call i64 @get_response(i32 %96, i16 signext %24)
br label %98
98: ; preds = %90, %95, %79
%99 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%100 = call i64 @compare_timevals(%struct.timeval* %5, %struct.timeval* %7)
%101 = icmp slt i64 %100, 0
br i1 %101, label %79, label %102
102: ; preds = %98
br label %20
}