#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
void *fun(void *arg) {
  int clifd = *(int *)arg;
  for (;;) {
    int n;
    char buffer[1024];
    n = recv(clifd, buffer, sizeof(buffer), 0);
    if (n < 0)
      break;
    if (n == 0) {
      close(clifd);
      printf("disconnect with clifd:%d\n", clifd);
      break;
    } else {
      buffer[n] = '\0';
      printf("%s\n", buffer);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1170 <fun+0x40>
jmp    11be <fun+0x8e>
cmpl   $0x0,-0x10(%rbp)
jne    1198 <fun+0x68>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11be <fun+0x8e>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1148 <fun+0x18>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    (%rdi),%ebp
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11b0 <fun+0x70>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %eax,%eax
je     1199 <fun+0x59>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    1170 <fun+0x30>
jmp    11b0 <fun+0x70>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"disconnect with clifd:%d\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i8* @fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %3
br label %9
9: ; preds = %30, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1024, i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %31
16: ; preds = %9
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %31
24: ; preds = %16
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %24
br label %9
31: ; preds = %19, %15
ret i8* null
}

LLVM IR (-O2):
@.str = [26 x i8] c"disconnect with clifd:%d\0A\00"
define noalias i8* @fun(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = call i32 @recv(i32 %4, i8* %5, i32 1024, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %1, %14
%9 = phi i32 [ %18, %14 ], [ %6, %1 ]
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @close(i32 %4)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %20
14: ; preds = %8
%15 = zext i32 %9 to i64
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i32 @puts(i8* %5)
%18 = call i32 @recv(i32 %4, i8* %5, i32 1024, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %14, %1, %11
ret i8* null
}