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

/* Variables and functions */
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
void get_response_message(char *_packet, int *_sock) {
  int total, received, bytes;
  char response[4096];
  memset(response, 0x00, sizeof(response));
  total = sizeof(response) - 1;
  received = 0;
  do {
    bytes = read(*_sock, response + received, total - received);
    if (bytes < 0)
      error_handling("ERROR reading response from socket");
    if (bytes == 0)
      break;
    received += bytes;
  } while (received < total);
  if (received == total)
    error_handling("ERROR storing complete response from socket");
  printf("Response: \n%s \n", response);
}


x86 assembly (clang, -O0):
<get_response_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
movl   $0xfff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ac <get_response_message+0x6c>
lea    0xe59(%rip),%rdi
call   1060 <error_handling@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11bb <get_response_message+0x7b>
jmp    11d0 <get_response_message+0x90>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1174 <get_response_message+0x34>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11e8 <get_response_message+0xa8>
lea    0xe40(%rip),%rdi
call   1060 <error_handling@plt>
lea    -0x1020(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_response_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r15
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
lea    0xe98(%rip),%r14
jmp    1182 <get_response_message+0x42>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <error_handling@plt>
add    %ebp,%ebx
cmp    $0xfff,%ebx
jge    11a2 <get_response_message+0x62>
mov    (%r15),%edi
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rsi
mov    $0xfff,%edx
sub    %eax,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1170 <get_response_message+0x30>
jne    1178 <get_response_message+0x38>
jmp    11b0 <get_response_message+0x70>
jne    11b0 <get_response_message+0x70>
lea    0xe78(%rip),%rdi
call   1060 <error_handling@plt>
lea    0xe98(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"ERROR reading response from socket\00"
@.str.1 = [44 x i8] c"ERROR storing complete response from socket\00"
@.str.2 = [16 x i8] c"Response: \0A%s \0A\00"
define void @get_response_message(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 4096)
store i32 4095, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %34, %2
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
%21 = call i32 @read(i32 %13, i8* %17, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 @error_handling(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %38
30: ; preds = %26
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = add nsw i32 %32, %31
store i32 %33, i32* %6
br label %34
34: ; preds = %30
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %11, label %38
38: ; preds = %34, %29
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @error_handling(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"ERROR reading response from socket\00"
@.str.1 = [44 x i8] c"ERROR storing complete response from socket\00"
@.str.2 = [16 x i8] c"Response: \0A%s \0A\00"
define void @get_response_message(i8* nocapture readnone %0, i32* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 4096)
br label %6
6: ; preds = %18, %2
%7 = phi i32 [ 0, %2 ], [ %19, %18 ]
%8 = load i32, i32* %1
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %9
%11 = sub nsw i32 4095, %7
%12 = call i32 @read(i32 %8, i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @error_handling(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %6
%17 = icmp eq i32 %12, 0
br i1 %17, label %25, label %18
18: ; preds = %14, %16
%19 = add nsw i32 %12, %7
%20 = icmp slt i32 %19, 4095
br i1 %20, label %6, label %21
21: ; preds = %18
%22 = icmp eq i32 %19, 4095
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = call i32 @error_handling(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %16, %23, %21
%26 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret void
}