#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 *, char, int);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int /*<<< orphan*/);
int read_response(int in_pipe, char *response) {
  char buf[1024];
  memset(buf, '\0', 1024);
  int read_success, attempts = 0;
  while (attempts++ < 20) {
    printf("attemtps: %d\n", attempts);
    read_success = read(in_pipe, buf, 1024);
    if (read_success != -1) {
      strncat(response, buf, strlen(buf));
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x418(%rbp)
mov    -0x418(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x418(%rbp)
cmp    $0x14,%eax
jge    121d <read_response+0xcd>
mov    -0x418(%rbp),%esi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
je     1218 <read_response+0xc8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x428(%rbp),%rdi
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
movl   $0x1,-0x4(%rbp)
jmp    1224 <read_response+0xd4>
jmp    117f <read_response+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_response>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%r12
xor    %r15d,%r15d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    $0x1,%ebp
lea    0xe79(%rip),%r13
nopw   0x0(%rax,%rax,1)
cmp    $0x15,%ebp
je     11d4 <read_response+0x84>
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
add    $0x1,%ebp
cmp    $0xffffffff,%eax
je     1190 <read_response+0x40>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"attemtps: %d\0A\00"
define i32 @read_response(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 1024)
store i32 0, i32* %8
br label %11
11: ; preds = %29, %2
%12 = load i32, i32* %8
%13 = add nsw i32 %12, 1
store i32 %13, i32* %8
%14 = icmp slt i32 %12, 20
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 1024)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @strncat(i8* %24, i8* %25, i32 %27)
store i32 1, i32* %3
br label %31
29: ; preds = %15
br label %11
30: ; preds = %11
store i32 0, i32* %3
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [14 x i8] c"attemtps: %d\0A\00"
define i32 @read_response(i32 %0, 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, i8 signext 0, i32 1024)
br label %6
6: ; preds = %10, %2
%7 = phi i32 [ 0, %2 ], [ %8, %10 ]
%8 = add nuw nsw i32 %7, 1
%9 = icmp eq i32 %7, 20
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
%12 = call i32 @read(i32 %0, i8* %4, i32 1024)
%13 = icmp eq i32 %12, -1
br i1 %13, label %6, label %14
14: ; preds = %10
%15 = call i32 @strlen(i8* %4)
%16 = call i32 @strncat(i8* %1, i8* %4, i32 %15)
br label %17
17: ; preds = %6, %14
%18 = phi i32 [ 1, %14 ], [ 0, %6 ]
ret i32 %18
}