#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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int waitForClose(int sockFd) {
  char buffer[1024] = {0};
  int sleepNum = 0;
  int sleepTime = 5;
  int status = -2;
  while (1) {
    status = recv(sockFd, buffer, sizeof buffer - 1, 0);
    if (status == 0) {
      return 1;
    } else {
      sleep(sleepTime);
      sleepNum += 1;
      if (sleepNum >= 100) {
        return 0;
      }
    }
    memset(buffer, 0, sizeof buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<waitForClose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x5,-0x418(%rbp)
movl   $0xfffffffe,-0x41c(%rbp)
ff ff ff
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jne    11a4 <waitForClose+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <waitForClose+0xc4>
mov    -0x418(%rbp),%edi
call   1050 <sleep@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
cmpl   $0x64,-0x414(%rbp)
jl     11d7 <waitForClose+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <waitForClose+0xc4>
jmp    11dc <waitForClose+0xac>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
jmp    116f <waitForClose+0x3f>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForClose>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%r15d
mov    %rsp,%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     11b9 <waitForClose+0x89>
mov    $0x64,%ebx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1050 <sleep@plt>
add    $0xffffffff,%ebx
je     11b6 <waitForClose+0x86>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    1180 <waitForClose+0x50>
jmp    11b9 <waitForClose+0x89>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @waitForClose(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = bitcast [1024 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 5, i32* %6
store i32 -2, i32* %7
br label %9
9: ; preds = %1, %25
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1023, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 1, i32* %2
br label %28
16: ; preds = %9
%17 = load i32, i32* %6
%18 = call i32 @sleep(i32 %17)
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp sge i32 %21, 100
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 0, i32* %2
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 1024)
br label %9
28: ; preds = %23, %15
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @waitForClose(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 1023, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1, %10
%7 = phi i32 [ %11, %10 ], [ 0, %1 ]
%8 = call i32 @sleep(i32 5)
%9 = icmp eq i32 %7, 99
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = add nuw nsw i32 %7, 1
%12 = call i32 @memset(i8* %3, i32 0, i32 1024)
%13 = call i32 @recv(i32 %0, i8* %3, i32 1023, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %10, %6, %1
%16 = phi i32 [ 1, %1 ], [ 0, %6 ], [ 1, %10 ]
ret i32 %16
}