#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 */

/* Variables and functions */
int send(int, char *, scalar_t__, int /*<<< orphan*/);
int send_req(int, int, scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strlen(char *);
int poll_server_p2(int sock, int wait) {
  int rv;
  char buf[8];
  snprintf(buf, 8, "%d", wait);
  rv = send_req(sock, 8, strlen(buf));
  if (rv < 0)
    return -1;
  if (send(sock, buf, strlen(buf), 0) != (int)strlen(buf))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<poll_server_p2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
lea    0xe9f(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
mov    $0x8,%esi
call   1060 <send_req@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    119e <poll_server_p2+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <poll_server_p2+0xb3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     11ec <poll_server_p2+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <poll_server_p2+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_server_p2>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ecx
mov    %edi,%ebx
lea    0xeb1(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    $0x8,%esi
mov    %rax,%rdx
call   1060 <send_req@plt>
test   %eax,%eax
js     11ac <poll_server_p2+0x6c>
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %ecx,%ebx
setne  %al
neg    %eax
jmp    11b1 <poll_server_p2+0x71>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @poll_server_p2(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %5
%10 = call i32 @snprintf(i8* %8, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
%14 = call i32 @send_req(i32 %11, i32 8, i64 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %30
18: ; preds = %2
%19 = load i32, i32* %4
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = call i32 @send(i32 %19, i8* %20, i64 %22, i32 0)
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
%27 = icmp ne i32 %23, %26
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 -1, i32* %3
br label %30
29: ; preds = %18
store i32 0, i32* %3
br label %30
30: ; preds = %29, %28, %17
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @poll_server_p2(i32 %0, i32 %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i64 @strlen(i8* %4)
%7 = call i32 @send_req(i32 %0, i32 8, i64 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = call i64 @strlen(i8* %4)
%11 = call i32 @send(i32 %0, i8* %4, i64 %10, i32 0)
%12 = call i64 @strlen(i8* %4)
%13 = trunc i64 %12 to i32
%14 = icmp ne i32 %11, %13
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %9, %2
%17 = phi i32 [ -1, %2 ], [ %15, %9 ]
ret i32 %17
}