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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
int do_local_client_step(int fd, void (*process)(char *buf)) {
  int numbytes;
  char buf[1024];
  memset(buf, 0, sizeof(buf));
  while ((numbytes = recv(fd, buf, sizeof(buf) - 1, 0)) > 0) {
    buf[sizeof(buf) - 1] = '\0';
    if (process)
      process(buf);
    memset(buf, 0, sizeof(buf));
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_local_client_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    119b <do_local_client_step+0x7b>
movb   $0x0,-0x21(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1183 <do_local_client_step+0x63>
mov    -0x10(%rbp),%rax
lea    -0x420(%rbp),%rdi
call   *%rax
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
jmp    1145 <do_local_client_step+0x25>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_local_client_step>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1199 <do_local_client_step+0x79>
mov    %rsp,%rbp
jmp    1185 <do_local_client_step+0x65>
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1199 <do_local_client_step+0x79>
movb   $0x0,0x3ff(%rsp)
test   %rbx,%rbx
je     1160 <do_local_client_step+0x40>
mov    %rbp,%rdi
call   *%rbx
jmp    1160 <do_local_client_step+0x40>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @do_local_client_step(i32 %0, void (i8*)* %1) {
%3 = alloca i32
%4 = alloca void (i8*)*
%5 = alloca i32
%6 = alloca [1024 x i8]
store i32 %0, i32* %3
store void (i8*)* %1, void (i8*)** %4
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1023, i32 0)
store i32 %12, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1023
store i8 0, i8* %15
%16 = load void (i8*)*, void (i8*)** %4
%17 = icmp ne void (i8*)* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load void (i8*)*, void (i8*)** %4
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %21
21: ; preds = %18, %14
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
br label %9
24: ; preds = %9
ret i32 0
}

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