#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 EOF;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int open_socket(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int d_sock, bytes_received;
  char buf[255], rec[256];
  d_sock = open_socket("127.0.0.1", "30000");
  bytes_received = recv(d_sock, rec, 255, 0);
  while (bytes_received) {
    if (bytes_received == EOF)
      error("can't read from server");
    rec[bytes_received] = '\0';
    printf("%s", rec);
    bytes_received = recv(d_sock, rec, 255, 0);
  }
  close(d_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11fd <main+0xad>
mov    -0x18(%rbp),%eax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
jne    11c0 <main+0x70>
lea    0xe55(%rip),%rdi
call   1070 <error@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
jmp    1198 <main+0x48>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,%r12d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     11ea <main+0x9a>
mov    %eax,%ebp
mov    0x2e53(%rip),%r13
lea    0xe74(%rip),%r14
lea    0xe84(%rip),%r15
mov    %rsp,%rbx
jmp    11da <main+0x8a>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11ea <main+0x9a>
cmp    0x0(%r13),%ebp
jne    11b0 <main+0x60>
mov    %r14,%rdi
call   1070 <error@plt>
jmp    11b0 <main+0x60>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"30000\00"
@EOF = global i32 0
@.str.2 = [23 x i8] c"can't read from server\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [255 x i8]
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @open_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%13 = call i32 @recv(i32 %11, i8* %12, i32 255, i32 0)
store i32 %13, i32* %7
br label %14
14: ; preds = %23, %2
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %7
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %6
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%31 = call i32 @recv(i32 %29, i8* %30, i32 255, i32 0)
store i32 %31, i32* %7
br label %14
32: ; preds = %14
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"30000\00"
@EOF = global i32 0
@.str.2 = [23 x i8] c"can't read from server\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @open_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @recv(i32 %5, i8* %4, i32 255, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %2, %14
%9 = phi i32 [ %18, %14 ], [ %6, %2 ]
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%18 = call i32 @recv(i32 %5, i8* %4, i32 255, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %14, %2
%21 = call i32 @close(i32 %5)
ret i32 0
}