#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*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, n;
  char recvline[4096], sendline[4096];
  struct sockaddr_in servaddr;
  if (argc != 2) {
    printf("usage: ./client <ipaddress>\n");
    exit(0);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("Create socket error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(8888);
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
    printf("inet_pton error for %s\n", argv[1]);
    exit(0);
  }
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("Connect error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  printf("Send msg to server: \n");
  fgets(sendline, 4096, stdin);
  if (send(sockfd, sendline, strlen(sendline), 0) < 0) {
    printf("Send msg error : %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f8 <main+0x38>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    124c <main+0x8c>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2028(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,-0x202c(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x2030(%rbp),%rdx
call   10a0 <inet_pton@plt>
cmp    $0x0,%rax
jg     12c2 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    130f <main+0x14f>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x2020(%rbp),%rdi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1090 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x203c(%rbp)
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2038(%rbp)
lea    -0x2020(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x203c(%rbp),%edi
mov    -0x2038(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    13a9 <main+0x1e9>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2c36(%rip),%rax
mov    (%rax),%edx
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
cmp    $0x2,%edi
jne    122b <main+0x5b>
mov    %rsi,%rbx
mov    0x2dfc(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    123e <main+0x6e>
mov    0x2dbe(%rip),%rbx
mov    (%rbx),%edi
call   10e0 <strerror@plt>
mov    (%rbx),%edx
lea    0xde6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    %eax,%r15d
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%rbp),%edi
mov    0x8(%rbx),%rsi
mov    %r14,%rdx
call   10b0 <inet_pton@plt>
test   %rax,%rax
jg     1295 <main+0xc5>
mov    0x8(%rbx),%rsi
lea    0xd9d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
jns    12c6 <main+0xf6>
mov    0x2d17(%rip),%rbx
mov    (%rbx),%edi
call   10e0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd7b(%rip),%rdi
jmp    121a <main+0x4a>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
jns    1325 <main+0x155>
mov    0x2cb8(%rip),%rbx
mov    (%rbx),%edi
call   10e0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd3a(%rip),%rdi
jmp    121a <main+0x4a>
mov    %r15d,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"usage: ./client <ipaddress>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"Create socket error: %s(errno: %d)\0A\00"
@errno = global i32 0
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [30 x i8] c"Connect error: %s(errno: %d)\0A\00"
@.str.4 = [22 x i8] c"Send msg to server: \0A\00"
@stdin = global i32 0
@.str.5 = [32 x i8] c"Send msg error : %s(errno: %d)\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 [4096 x i8]
%9 = alloca [4096 x 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 ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = load i32, i32* @errno
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %16
%28 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %29, i32* %30
%31 = call i32 @htons(i32 8888)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %31, i32* %32
%33 = load i32, i32* @AF_INET
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%38 = call i64 @inet_pton(i32 %33, i8* %36, i32* %37)
%39 = icmp sle i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %27
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %27
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%49 = call i64 @connect(i32 %47, %struct.sockaddr* %48, i32 12)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %46
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = load i32, i32* @errno
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %53, i32 %54)
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %46
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%60 = load i32, i32* @stdin
%61 = call i32 @fgets(i8* %59, i32 4096, i32 %60)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = call i64 @send(i32 %62, i8* %63, i32 %65, i32 0)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %57
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = load i32, i32* @errno
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %70, i32 %71)
%73 = call i32 @exit(i32 0)
unreachable
74: ; preds = %57
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
%77 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"Create socket error: %s(errno: %d)\0A\00"
@errno = global i32 0
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [30 x i8] c"Connect error: %s(errno: %d)\0A\00"
@stdin = global i32 0
@.str.5 = [32 x i8] c"Send msg error : %s(errno: %d)\0A\00"
@str = [21 x i8] c"Send msg to server: \00"
@str.6 = [28 x i8] c"usage: ./client <ipaddress>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %11
%23 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 8888)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%32 = call i64 @inet_pton(i32 %28, i8* %30, i32* %31)
%33 = icmp slt i64 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %22
%35 = load i8*, i8** %29
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %22
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%40 = call i64 @connect(i32 %14, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = load i32, i32* @errno
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45)
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %38
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%50 = load i32, i32* @stdin
%51 = call i32 @fgets(i8* %5, i32 4096, i32 %50)
%52 = call i32 @strlen(i8* %5)
%53 = call i64 @send(i32 %14, i8* %5, i32 %52, i32 0)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %48
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = load i32, i32* @errno
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %57, i32 %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %48
%62 = call i32 @close(i32 %14)
%63 = call i32 @exit(i32 0)
unreachable
}