#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 */
scalar_t__ EOF;
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int print_tcp_response(int sockfd) {
  int bytes_read = 0;
  char buffer[1024];
  memset(buffer, '0', sizeof(buffer));
  while ((bytes_read = read(sockfd, buffer, sizeof(buffer) - 1)) > 0) {
    buffer[bytes_read] = 0;
    if (fputs(buffer, stdout) == EOF) {
      return -1;
    }
    printf("\n");
  }
  if (bytes_read < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<print_tcp_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11d9 <print_tcp_response+0x99>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <print_tcp_response+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <print_tcp_response+0xb6>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
jmp    116b <print_tcp_response+0x2b>
cmpl   $0x0,-0xc(%rbp)
jge    11ef <print_tcp_response+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <print_tcp_response+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_tcp_response>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11c3 <print_tcp_response+0x83>
mov    0x2e5a(%rip),%r14
mov    %rsp,%rbx
mov    0x2e60(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    (%r15),%rax
je     11c9 <print_tcp_response+0x89>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     1190 <print_tcp_response+0x50>
neg    %eax
sbb    %eax,%eax
jmp    11ce <print_tcp_response+0x8e>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@EOF = global i64 0
@.str = [2 x i8] c"\0A\00"
define i32 @print_tcp_response(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 48, i32 1024)
br label %8
8: ; preds = %23, %1
%9 = load i32, i32* %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 1023)
store i32 %11, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %8
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* @stdout
%19 = call i64 @fputs(i8* %17, i32 %18)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %2
br label %30
23: ; preds = %13
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %8
25: ; preds = %8
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 -1, i32* %2
br label %30
29: ; preds = %25
store i32 0, i32* %2
br label %30
30: ; preds = %29, %28, %22
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i64 0
define i32 @print_tcp_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 48, i32 1024)
%5 = call i32 @read(i32 %0, i8* %3, i32 1023)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1, %15
%8 = phi i32 [ %17, %15 ], [ %5, %1 ]
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = load i32, i32* @stdout
%12 = call i64 @fputs(i8* %3, i32 %11)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %23, label %15
15: ; preds = %7
%16 = call i32 @putchar(i32 10)
%17 = call i32 @read(i32 %0, i8* %3, i32 1023)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %15, %1
%20 = phi i32 [ %5, %1 ], [ %17, %15 ]
%21 = icmp ne i32 %20, 0
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %7, %19
%24 = phi i32 [ %22, %19 ], [ -1, %7 ]
ret i32 %24
}