#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
void read_message(int client_socket) {
  char recv_buf[1024];
  memset(recv_buf, 0, 1024);
  int bytes;
  bytes = recv(client_socket, recv_buf, 1024, 0);
  if (bytes > 0) {
    printf("%s", recv_buf);
  } else {
    if (bytes == 0) {
      printf("Remote server closed connection.\n");
      close(client_socket);
      exit(1);
    }
    perror("recv() failed");
  }
}


x86 assembly (clang, -O0):
<read_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    11c4 <read_message+0x64>
lea    -0x410(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <read_message+0x9d>
cmpl   $0x0,-0x414(%rbp)
jne    11f1 <read_message+0x91>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_message>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11bd <read_message+0x4d>
lea    0xe57(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
je     11cd <read_message+0x5d>
lea    0xe3d(%rip),%rdi
call   1080 <perror@plt>
jmp    11b3 <read_message+0x43>
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [34 x i8] c"Remote server closed connection.\0A\00"
@.str.2 = [14 x i8] c"recv() failed\00"
define void @read_message(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 1024)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i32 @recv(i32 %7, i8* %8, i32 1024, i32 0)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %25
15: ; preds = %1
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"recv() failed\00"
@str = [33 x i8] c"Remote server closed connection.\00"
define void @read_message(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 i32 @recv(i32 %0, i8* %3, i32 1024, i32 0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %17
9: ; preds = %1
%10 = icmp eq i32 %5, 0
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%13 = call i32 @close(i32 %0)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %7
ret void
}