#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ myaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int server_fd;
  struct sockaddr_in myaddr;
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  myaddr.sin_port = htons(8080);
  char buf[100];
  server_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_fd == -1) {
    perror("socket error");
    exit(1);
  }
  if (connect(server_fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1) {
    perror("connect error");
    exit(1);
  }
  recv(server_fd, buf, 100, 0);
  printf("get message : %s\n", buf);
  close(server_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe4b(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1206 <main+0x76>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1236 <main+0xa6>
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x80(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e4a(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe55(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1224 <main+0x94>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     122d <main+0x9d>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xe1a(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xddf(%rip),%rdi
jmp    1234 <main+0xa4>
lea    0xde3(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [14 x i8] c"connect error\00"
@.str.3 = [18 x i8] c"get message : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %5, i32* %6
%7 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%9 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = call i32 @htons(i32 8080)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* %2
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = call i32 @recv(i32 %29, i8* %30, i32 100, i32 0)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %2
%35 = call i32 @close(i32 %34)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [14 x i8] c"connect error\00"
@.str.3 = [18 x i8] c"get message : %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %4, i32* %5
%6 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %6, i32* %7
%8 = tail call i32 @htons(i32 8080)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%20 = call i32 @connect(i32 %13, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i32 @recv(i32 %13, i8* %10, i32 100, i32 0)
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%28 = call i32 @close(i32 %13)
ret i32 0
}