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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct sockaddr_in servaddr;
  char buf[80];
  int sockfd, n;
  char *str;
  if (argc != 2) {
    fputs("usage: ./client message\n", stderr);
    exit(1);
  }
  str = argv[1];
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr);
  servaddr.sin_port = htons(8000);
  connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c2 <main+0x42>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x74(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xdfd(%rip),%rsi
call   1060 <inet_pton@plt>
mov    $0x1f40,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x74(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    -0x74(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1201 <main+0x81>
mov    0x2e53(%rip),%r15
mov    (%r15),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    (%r15),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
lea    0xe4c(%rip),%rsi
call   1060 <inet_pton@plt>
mov    $0x1f40,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"usage: ./client message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%18 = call i32 @inet_pton(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = call i32 @htons(i32 8000)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @connect(i32 %13, %struct.sockaddr* %21, i32 12)
%23 = call i32 @close(i32 %13)
ret i32 0
}