#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 STDOUT_FILENO;
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 /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
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));
  write(sockfd, str, strlen(str));
  n = read(sockfd, buf, 80);
  printf("Response from server:\n");
  write(STDOUT_FILENO, buf, n);
  write(STDOUT_FILENO, "\n", 1);
  printf("call close\n");
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1202 <main+0x42>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe0d(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x74(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xdbd(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    $0x1f40,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x74(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x74(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x50,%edx
call   1090 <read@plt>
mov    %eax,-0x78(%rbp)
lea    0xd58(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%edx
call   1030 <write@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xd34(%rip),%rdi
call   1060 <printf@plt>
mov    -0x74(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jne    12b5 <main+0xf5>
mov    0x8(%rsi),%r14
mov    0x2e02(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x0(%rbp),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
lea    0xe03(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1090 <read@plt>
mov    %eax,%ebp
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d7c(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    (%r15),%edi
lea    0xd8c(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xd9d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    0xd3b(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <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"
@.str.2 = [23 x i8] c"Response from server:\0A\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [12 x i8] c"call close\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 [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 = load i8*, i8** %10
%37 = load i8*, i8** %10
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @write(i32 %35, i8* %36, i32 %38)
%40 = load i32, i32* %8
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 80)
store i32 %42, i32* %9
%43 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @STDOUT_FILENO
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%46 = load i32, i32* %9
%47 = call i32 @write(i32 %44, i8* %45, i32 %46)
%48 = load i32, i32* @STDOUT_FILENO
%49 = call i32 @write(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%50 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
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"
@STDOUT_FILENO = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@str = [22 x i8] c"Response from server:\00"
@str.5 = [11 x i8] c"call close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [80 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fputs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%22 = call i32 @inet_pton(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = call i32 @htons(i32 8000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @connect(i32 %17, %struct.sockaddr* %25, i32 12)
%27 = call i32 @strlen(i8* %14)
%28 = call i32 @write(i32 %17, i8* %14, i32 %27)
%29 = call i32 @read(i32 %17, i8* %6, i32 80)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* @STDOUT_FILENO
%32 = call i32 @write(i32 %31, i8* %6, i32 %29)
%33 = load i32, i32* @STDOUT_FILENO
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
%36 = call i32 @close(i32 %17)
ret i32 0
}