#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ testPoll(struct sockaddr_in *);
int main(void) {
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(4375);
  if (inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr) <= 0) {
    fprintf(stderr, "inet_pton error");
    exit(EXIT_FAILURE);
  }
  printf("Testing Poll-message for %d times...\n", 100);
  for (int i = 0; i < 100; i++) {
    printf("Test %d/%d...\n", i + 1, 100);
    if (!testPoll(&servaddr)) {
      printf("Test failed!\n");
      exit(EXIT_FAILURE);
    }
  }
  printf("Test passed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1117,%edi
call   1030 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
call   1070 <inet_pton@plt>
cmp    $0x0,%rax
jg     11ee <main+0x7e>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe25(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    126c <main+0xfc>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe21(%rip),%rdi
mov    $0x64,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1090 <testPoll@plt>
cmp    $0x0,%eax
jne    1259 <main+0xe9>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    125e <main+0xee>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1208 <main+0x98>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e46(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x1117,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe41(%rip),%rsi
mov    %r14,%rdx
call   1080 <inet_pton@plt>
test   %rax,%rax
jle    1247 <main+0xc7>
lea    0xe47(%rip),%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
lea    0xe55(%rip),%r14
mov    %rsp,%r15
xchg   %ax,%ax
cmp    $0x65,%ebx
je     122f <main+0xaf>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   10a0 <testPoll@plt>
add    $0x1,%ebx
test   %eax,%eax
jne    11f0 <main+0x70>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1221 <main+0xa1>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"inet_pton error\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [38 x i8] c"Testing Poll-message for %d times...\0A\00"
@.str.3 = [15 x i8] c"Test %d/%d...\0A\00"
@.str.4 = [14 x i8] c"Test failed!\0A\00"
@.str.5 = [14 x i8] c"Test passed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %5, i32* %6
%7 = call i32 @htons(i32 4375)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%11 = call i64 @inet_pton(i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = icmp sle i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 100)
store i32 0, i32* %3
br label %20
20: ; preds = %34, %18
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 100
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 100)
%27 = call i32 @testPoll(%struct.sockaddr_in* %2)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %20
37: ; preds = %20
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"inet_pton error\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [38 x i8] c"Testing Poll-message for %d times...\0A\00"
@.str.3 = [15 x i8] c"Test %d/%d...\0A\00"
@str = [13 x i8] c"Test passed!\00"
@str.6 = [13 x i8] c"Test failed!\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %4, i32* %5
%6 = call i32 @htons(i32 4375)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%10 = call i64 @inet_pton(i32 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = icmp slt i64 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 100)
br label %19
19: ; preds = %24, %17
%20 = phi i32 [ 0, %17 ], [ %25, %24 ]
%21 = icmp eq i32 %20, 100
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret i32 0
24: ; preds = %19
%25 = add nuw nsw i32 %20, 1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 100)
%27 = call i32 @testPoll(%struct.sockaddr_in* %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %19
29: ; preds = %24
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
}