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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atof(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sock, port;
  char *host, *msg;
  struct sockaddr_in sa;
  if (argc < 3) {
    printf("Usage: client <host> <port> [<message>]\n");
    exit(-1);
  }
  host = argv[1];
  port = atof(argv[2]);
  if (argc == 3)
    msg = "Let me try ...";
  else
    msg = argv[3];
  memset(&sa, 0, sizeof(struct sockaddr_in));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(port);
  sa.sin_addr.s_addr = inet_addr(host);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("Creating the socket");
    exit(-1);
  }
  if (connect(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
    perror("Binding");
    exit(-1);
  }
  if (send(sock, msg, strlen(msg), 0) < 0) {
    perror("Writeing");
    exit(-1);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f6 <main+0x36>
lea    0xe19(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    122c <main+0x6c>
lea    0xe06(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1238 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a7 <main+0xe7>
lea    0xda0(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12d8 <main+0x118>
lea    0xd83(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x0,%rax
jge    131f <main+0x15f>
lea    0xd44(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jle    128f <main+0xcf>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   1040 <atof@plt>
mov    %eax,%r15d
cmp    $0x3,%ebp
jne    11f6 <main+0x36>
lea    0xe0c(%rip),%rbx
jmp    11fa <main+0x3a>
mov    0x18(%rbx),%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dd6(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12a5 <main+0xe5>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     12ae <main+0xee>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     12b7 <main+0xf7>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xd63(%rip),%rdi
jmp    12be <main+0xfe>
lea    0xd6e(%rip),%rdi
jmp    12be <main+0xfe>
lea    0xd6d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [41 x i8] c"Usage: client <host> <port> [<message>]\0A\00"
@.str.1 = [15 x i8] c"Let me try ...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [20 x i8] c"Creating the socket\00"
@.str.3 = [8 x i8] c"Binding\00"
@.str.4 = [9 x i8] c"Writeing\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 i8*
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atof(i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %27
26: ; preds = %16
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %31
27: ; preds = %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
store i8* %30, i8** %9
br label %31
31: ; preds = %27, %26
%32 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* %7
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %36, i32* %37
%38 = load i8*, i8** %8
%39 = call i32 @inet_addr(i8* %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i32 %39, i32* %41
%42 = load i32, i32* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @socket(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %31
%48 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %31
%51 = load i32, i32* %6
%52 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%53 = call i64 @connect(i32 %51, %struct.sockaddr* %52, i32 12)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %50
%59 = load i32, i32* %6
%60 = load i8*, i8** %9
%61 = load i8*, i8** %9
%62 = call i32 @strlen(i8* %61)
%63 = call i64 @send(i32 %59, i8* %60, i32 %62, i32 0)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 -1)
unreachable
68: ; preds = %58
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [15 x i8] c"Let me try ...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [20 x i8] c"Creating the socket\00"
@.str.3 = [8 x i8] c"Binding\00"
@.str.4 = [9 x i8] c"Writeing\00"
@str = [40 x i8] c"Usage: client <host> <port> [<message>]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atof(i8* %13)
%15 = icmp eq i32 %0, 3
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
br label %19
19: ; preds = %9, %16
%20 = phi i8* [ %18, %16 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %9 ]
%21 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 %14)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = call i32 @inet_addr(i8* %11)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %19
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = call i64 @connect(i32 %30, %struct.sockaddr* %36, i32 12)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %35
%43 = call i32 @strlen(i8* %20)
%44 = call i64 @send(i32 %30, i8* %20, i32 %43, i32 0)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %42
%50 = call i32 @close(i32 %30)
ret i32 0
}