#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 member_0;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int /*<<< orphan*/ anp_close(int);
int anp_read(int, char *, int);
int /*<<< orphan*/ dump_bytes(char *, int);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ printf(char *, ...);
void client_loop(int fd) {
  static char buf[256];
  int nbytes;
  int old_flags;
  struct timeval timeout = {3600, 0};
  while (1) {
    if ((nbytes = anp_read(fd, buf, 256)) < 0) {
      err_sys("client read");
    } else {
      if (nbytes == 0) {
        printf("server closed connection.\n");
        anp_close(fd);
        return;
      }
      printf("client read %d bytes from server: ", nbytes);
      dump_bytes(buf, nbytes);
    }
  }
}


x86 assembly (clang, -O0):
<client_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    0x2ef0(%rip),%rsi
mov    $0x100,%edx
call   1050 <anp_read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1197 <client_loop+0x47>
lea    0xe7b(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11dd <client_loop+0x8d>
cmpl   $0x0,-0x8(%rbp)
jne    11bd <client_loop+0x6d>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1070 <anp_close@plt>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0x2e88(%rip),%rdi
call   1060 <dump_bytes@plt>
jmp    1166 <client_loop+0x16>

x86 assembly (clang, -O2):
<client_loop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
lea    0x2eef(%rip),%r14
lea    0xe88(%rip),%r15
lea    0xe8d(%rip),%r12
jmp    1198 <client_loop+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <err_sys@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1060 <anp_read@plt>
test   %eax,%eax
js     1190 <client_loop+0x30>
je     11c7 <client_loop+0x67>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <dump_bytes@plt>
jmp    1198 <client_loop+0x38>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <anp_close@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@client_loop.buf = internal global [256 x i8] zeroinitializer
@__const.client_loop.timeout = %struct.timeval { i32 3600, i32 0 }
@.str = [12 x i8] c"client read\00"
@.str.1 = [27 x i8] c"server closed connection.\0A\00"
@.str.2 = [35 x i8] c"client read %d bytes from server: \00"
define void @client_loop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
store i32 %0, i32* %2
%6 = bitcast %struct.timeval* %5 to i8*
br label %7
7: ; preds = %1, %25
%8 = load i32, i32* %2
%9 = call i32 @anp_read(i32 %8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @client_loop.buf, i64 0, i64 0), i32 256)
store i32 %9, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %25
13: ; preds = %7
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = call i32 @anp_close(i32 %18)
ret void
20: ; preds = %13
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @dump_bytes(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @client_loop.buf, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %20, %11
br label %7
}

LLVM IR (-O2):
@client_loop.buf = internal global [256 x i8] zeroinitializer
@.str = [12 x i8] c"client read\00"
@.str.2 = [35 x i8] c"client read %d bytes from server: \00"
@str = [26 x i8] c"server closed connection.\00"
define void @client_loop(i32 %0) {
br label %2
2: ; preds = %15, %1
%3 = tail call i32 @anp_read(i32 %0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @client_loop.buf, i64 0, i64 0), i32 256)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %2
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @anp_close(i32 %0)
ret void
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%14 = tail call i32 @dump_bytes(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @client_loop.buf, i64 0, i64 0), i32 %3)
br label %15
15: ; preds = %12, %5
br label %2
}