#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 */
typedef int /*<<< orphan*/ uint32_t;
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ port_string;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getaddrinfo(char *, char *, int /*<<< orphan*/, struct addrinfo **);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int r, s;
  struct addrinfo *ai;
  char buf[512];
  char port_string[sizeof(uint32_t) + 1];
  assert(argc == 3);
  assert(strlen(argv[2]) < sizeof(buf));
  r = snprintf(port_string, sizeof(port_string), "%d", 2041);
  assert(r < sizeof(port_string));
  r = getaddrinfo(argv[1], port_string, 0, &ai);
  assert(r != -1);
  s = socket(ai->ai_family, SOCK_STREAM, 0);
  assert(s != -1);
  r = connect(s, ai->ai_addr, ai->ai_addrlen);
  assert(r != -1);
  fprintf(stderr, "Got connection...\n");
  r = write(s, argv[2], strlen(argv[2]) + 1);
  assert(r != -1);
  fprintf(stderr, "Wrote arg...\n");
  r = read(s, buf, strlen(argv[2]) + 1);
  assert(r == strlen(argv[2]) + 1);
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x200,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x225(%rbp),%rdi
mov    $0x5,%esi
lea    0xe01(%rip),%rdx
mov    $0x7f9,%ecx
call   1060 <snprintf@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x5,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x225(%rbp),%rsi
xor    %edx,%edx
lea    -0x20(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10a0 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x248(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x23c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x22c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x22c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x220(%rbp),%rsi
lea    0xc8b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
xor    %eax,%eax
cmp    $0x3,%edi
sete   %al
mov    %eax,%edi
call   1080 <assert@plt>
mov    0x10(%r14),%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    $0x200,%eax
setb   %dil
call   1080 <assert@plt>
lea    0xe21(%rip),%rdx
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x5,%esi
mov    $0x7f9,%ecx
call   1060 <snprintf@plt>
xor    %edi,%edi
cmp    $0x5,%eax
setb   %dil
call   1080 <assert@plt>
mov    0x8(%r14),%rdi
mov    %rsp,%rcx
mov    %rbp,%rsi
xor    %edx,%edx
call   10b0 <getaddrinfo@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10a0 <connect@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    0x2d71(%rip),%r15
mov    (%r15),%edi
lea    0xd8a(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    (%r15),%edi
lea    0xd67(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x10(%r14),%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
xor    %edi,%edi
cmp    %eax,%ebp
sete   %dil
call   1080 <assert@plt>
lea    0xd33(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Got connection...\0A\00"
@.str.2 = [14 x i8] c"Wrote arg...\0A\00"
@.str.3 = [4 x i8] c"%s\0A\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 %struct.addrinfo*
%9 = alloca [512 x i8]
%10 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 3
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = icmp ult i64 %19, 512
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%24 = call i32 @snprintf(i8* %23, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2041)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = icmp ult i64 %26, 5
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%34 = call i32 @getaddrinfo(i8* %32, i8* %33, i32 0, %struct.addrinfo** %8)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, -1
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load %struct.addrinfo*, %struct.addrinfo** %8
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = load i32, i32* @SOCK_STREAM
%43 = call i32 @socket(i32 %41, i32 %42, i32 0)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, -1
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* %7
%49 = load %struct.addrinfo*, %struct.addrinfo** %8
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %8
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i32 @connect(i32 %48, i32 %51, i32 %54)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, -1
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32, i32* %7
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @strlen(i8* %68)
%70 = add nsw i32 %69, 1
%71 = call i32 @write(i32 %62, i8* %65, i32 %70)
store i32 %71, i32* %6
%72 = load i32, i32* %6
%73 = icmp ne i32 %72, -1
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%78 = load i32, i32* %7
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 2
%82 = load i8*, i8** %81
%83 = call i32 @strlen(i8* %82)
%84 = add nsw i32 %83, 1
%85 = call i32 @read(i32 %78, i8* %79, i32 %84)
store i32 %85, i32* %6
%86 = load i32, i32* %6
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 2
%89 = load i8*, i8** %88
%90 = call i32 @strlen(i8* %89)
%91 = add nsw i32 %90, 1
%92 = icmp eq i32 %86, %91
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%96 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %95)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Got connection...\0A\00"
@.str.2 = [14 x i8] c"Wrote arg...\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca [512 x i8]
%5 = alloca [5 x i8]
%6 = bitcast %struct.addrinfo** %3 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %13)
%15 = icmp ult i32 %14, 512
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = call i32 @snprintf(i8* %8, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2041)
%19 = icmp ult i32 %18, 5
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @getaddrinfo(i8* %23, i8* %8, i32 0, %struct.addrinfo** %3)
%25 = icmp ne i32 %24, -1
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load %struct.addrinfo*, %struct.addrinfo** %3
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 2
%30 = load i32, i32* %29
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
%33 = icmp ne i32 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load %struct.addrinfo*, %struct.addrinfo** %3
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @connect(i32 %32, i32 %38, i32 %40)
%42 = icmp ne i32 %41, -1
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%47 = load i8*, i8** %12
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %48, 1
%50 = call i32 @write(i32 %32, i8* %47, i32 %49)
%51 = icmp ne i32 %50, -1
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8*, i8** %12
%57 = call i32 @strlen(i8* %56)
%58 = add nsw i32 %57, 1
%59 = call i32 @read(i32 %32, i8* %7, i32 %58)
%60 = load i8*, i8** %12
%61 = call i32 @strlen(i8* %60)
%62 = add nsw i32 %61, 1
%63 = icmp eq i32 %59, %62
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
ret i32 0
}