#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 */
typedef int /*<<< orphan*/ u_short;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ s_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int main(int argc, char const *argv[]) {
  struct sockaddr_in s_addr, c_addr;
  char buffer[1024];
  int sfd, n;
  memset((char *)&s_addr, 0, sizeof(s_addr));
  s_addr.sin_family = AF_INET;
  s_addr.sin_port = htons((u_short)9503);
  s_addr.sin_addr.s_addr = INADDR_ANY;
  if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("%s\n", "socket() error");
    exit(1);
  };
  if (connect(sfd, (struct sockaddr *)&s_addr, sizeof(s_addr)) < 0) {
    printf("%s\n", "connect() error");
    exit(1);
  };
  if (write(sfd, "hello", 5) < 0) {
    printf("%s\n", "send() error");
    exit(1);
  }
  if ((n = read(sfd, buffer, 1024)) < 0) {
    printf("%s\n", "recv() error");
    exit(1);
  };
  write(1, buffer, n);
  printf("Exiting ...\n");
  close(sfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x251f,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x434(%rbp)
cmp    $0x0,%eax
jge    1225 <main+0x95>
lea    0xdf3(%rip),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x434(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1262 <main+0xd2>
lea    0xdb6(%rip),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x434(%rbp),%edi
lea    0xdb4(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12a2 <main+0x112>
lea    0xd76(%rip),%rdi
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x434(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x438(%rbp)
cmp    $0x0,%eax
jge    12e7 <main+0x157>
lea    0xd31(%rip),%rdi
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x430(%rbp),%rsi
mov    -0x438(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e3a(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x251f,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1256 <main+0xc6>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     125f <main+0xcf>
lea    0xe1e(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1268 <main+0xd8>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1271 <main+0xe1>
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
ret
lea    0xda3(%rip),%rdi
jmp    1278 <main+0xe8>
lea    0xda9(%rip),%rdi
jmp    1278 <main+0xe8>
lea    0xdb6(%rip),%rdi
jmp    1278 <main+0xe8>
lea    0xdba(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [16 x i8] c"connect() error\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [13 x i8] c"send() error\00"
@.str.5 = [13 x i8] c"recv() error\00"
@.str.6 = [13 x i8] c"Exiting ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast %struct.sockaddr_in* %6 to i8*
%12 = call i32 @memset(i8* %11, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 9503)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i32, i32* %9
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = load i32, i32* %9
%37 = call i64 @write(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
%43 = load i32, i32* %9
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 1024)
store i32 %45, i32* %10
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %42
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %10
%53 = call i64 @write(i32 1, i8* %51, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [16 x i8] c"connect() error\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [13 x i8] c"send() error\00"
@.str.5 = [13 x i8] c"recv() error\00"
@str = [12 x i8] c"Exiting ...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i32 0, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @htons(i32 9503)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i64 @connect(i32 %16, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i64 @write(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %28
%35 = call i32 @read(i32 %16, i8* %6, i32 1024)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
%41 = call i64 @write(i32 1, i8* %6, i32 %35)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%43 = call i32 @close(i32 %16)
ret i32 0
}