#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 /*<<< orphan*/ printf(char *, char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int print_response(int sockfd) {
  int bufsize = 1024, read, total_read = 0;
  char buf[bufsize];
  memset(buf, 0, bufsize);
  while (read = recv(sockfd, buf, bufsize, 0) > 0) {
    printf("%s", buf);
    memset(buf, 0, read);
    total_read += read;
  }
}


x86 assembly (clang, -O0):
<print_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x400,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x10(%rbp)
test   $0x1,%al
jne    11a9 <print_response+0x79>
jmp    11d5 <print_response+0xa5>
mov    -0x30(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <print_response+0x49>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_response>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    11a0 <print_response+0x70>
lea    0xe94(%rip),%r14
mov    %rsp,%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jg     1170 <print_response+0x40>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @print_response(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %3
store i32 1024, i32* %4
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
%13 = load i32, i32* %4
%14 = call i32 @memset(i8* %12, i32 0, i32 %13)
br label %15
15: ; preds = %21, %1
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i64 @recv(i32 %16, i8* %12, i32 %17, i32 0)
%19 = icmp sgt i64 %18, 0
%20 = zext i1 %19 to i32
store i32 %20, i32* %5
br i1 %19, label %21, label %28
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%23 = load i32, i32* %5
%24 = call i32 @memset(i8* %12, i32 0, i32 %23)
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add nsw i32 %26, %25
store i32 %27, i32* %6
br label %15
28: ; preds = %15
%29 = load i8*, i8** %7
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @print_response(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 1024)
%5 = call i64 @recv(i32 %0, i8* %3, i32 1024, i32 0)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1, %7
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = call i32 @memset(i8* %3, i32 0, i32 1)
%10 = call i64 @recv(i32 %0, i8* %3, i32 1024, i32 0)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7, %1
ret i32 undef
}