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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Connect(int, struct sockaddr *, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ str_cli(int);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in servaddr;
  if (argc != 2)
    err_quit("usage: client <IPaddress>");
  sockfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5780);
  inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
  Connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  str_cli(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ac <main+0x2c>
lea    0xe59(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1694,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    -0x14(%rbp),%edi
call   1050 <str_cli@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     119e <main+0x1e>
lea    0xe67(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2e43(%rip),%r15
mov    (%r15),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x1694,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%edi
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
call   1070 <inet_pton@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    %ebp,%edi
call   1050 <str_cli@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"usage: client <IPaddress>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @err_quit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @Socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 5780)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%26 = call i32 @inet_pton(i32 %21, i8* %24, i32* %25)
%27 = load i32, i32* %6
%28 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%29 = call i32 @Connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = load i32, i32* %6
%31 = call i32 @str_cli(i32 %30)
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"usage: client <IPaddress>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @err_quit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @Socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 5780)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%21 = call i32 @inet_pton(i32 %17, i8* %19, i32* %20)
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @Connect(i32 %11, %struct.sockaddr* %22, i32 12)
%24 = call i32 @str_cli(i32 %11)
%25 = call i32 @exit(i32 0)
unreachable
}