#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  int sock, msg_len, n;
  struct sockaddr_in sa;
  char *server_ip;
  char msg[512], buf[1024];
  if (argc != 2) {
    fprintf(stderr, "usage: echo_client1 SEVER_IP_ADDRESS\n");
    exit(1);
  }
  server_ip = argv[1];
  sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  memset(&sa, 0, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(49152);
  sa.sin_addr.s_addr = inet_addr(server_ip);
  if (connect(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
    fprintf(stderr, "connect() failuer\n");
    exit(1);
  }
  printf("please input a message!\n");
  printf("> ");
  scanf("%s", msg);
  msg_len = strlen(msg);
  if (send(sock, msg, msg_len, 0) != msg_len) {
    fprintf(stderr, "send() failuer\n");
    exit(1);
  }
  if ((n = recv(sock, buf, sizeof(buf), 0)) > 0) {
    buf[n] = '\0';
    printf("Echo message: ");
    printf("%s\n", buf);
  } else if (n < 0) {
    fprintf(stderr, "recv() failuer\n");
    exit(1);
  }
  printf("\n");
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1212 <main+0x42>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0xc000,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    12b0 <main+0xe0>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x230(%rbp),%rsi
lea    0xd7b(%rip),%rdi
call   10c0 <scanf@plt>
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    -0x18(%rbp),%eax
je     132a <main+0x15a>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1380 <main+0x1b0>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x630(%rbp,%rax,1)
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x630(%rbp),%rsi
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13ae <main+0x1de>
cmpl   $0x0,-0x1c(%rbp)
jge    13a9 <main+0x1d9>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    0xce1(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13ae <main+0x1de>
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x610,%rsp
cmp    $0x2,%edi
jne    1331 <main+0x141>
mov    0x8(%rsi),%r14
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,%r12d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0xc000,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
call   10c0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1100 <connect@plt>
test   %rax,%rax
js     1343 <main+0x153>
lea    0xde7(%rip),%rdi
call   1050 <puts@plt>
lea    0xda6(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd9b(%rip),%rdi
lea    0x410(%rsp),%rbx
mov    %rbx,%rsi
call   10e0 <scanf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    %ebp,%eax
jne    1355 <main+0x165>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    130b <main+0x11b>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd57(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x10(%rsp),%rdi
call   1050 <puts@plt>
jmp    130d <main+0x11d>
js     1367 <main+0x177>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x610,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xcbf(%rip),%rsi
jmp    1377 <main+0x187>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xcd3(%rip),%rsi
jmp    1377 <main+0x187>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
jmp    1377 <main+0x187>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [38 x i8] c"usage: echo_client1 SEVER_IP_ADDRESS\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AF_INET = global i32 0
@.str.1 = [19 x i8] c"connect() failuer\0A\00"
@.str.2 = [25 x i8] c"please input a message!\0A\00"
@.str.3 = [3 x i8] c"> \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [16 x i8] c"send() failuer\0A\00"
@.str.6 = [15 x i8] c"Echo message: \00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [16 x i8] c"recv() failuer\0A\00"
@.str.9 = [2 x i8] c"\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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i8*
%11 = alloca [512 x i8]
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %10
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = load i32, i32* @IPPROTO_TCP
%26 = call i32 @socket(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %6
%27 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %28, i32* %29
%30 = call i32 @htons(i32 49152)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i8*, i8** %10
%33 = call i32 @inet_addr(i8* %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%38 = call i64 @connect(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %19
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %19
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %7
%51 = load i32, i32* %6
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%53 = load i32, i32* %7
%54 = call i32 @send(i32 %51, i8* %52, i32 %53, i32 0)
%55 = load i32, i32* %7
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %44
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %44
%62 = load i32, i32* %6
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%64 = call i32 @recv(i32 %62, i8* %63, i32 1024, i32 0)
store i32 %64, i32* %8
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %61
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %68
store i8 0, i8* %69
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %71)
br label %81
73: ; preds = %61
%74 = load i32, i32* %8
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %73
br label %81
81: ; preds = %80, %66
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [38 x i8] c"usage: echo_client1 SEVER_IP_ADDRESS\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AF_INET = global i32 0
@.str.1 = [19 x i8] c"connect() failuer\0A\00"
@.str.3 = [3 x i8] c"> \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [16 x i8] c"send() failuer\0A\00"
@.str.6 = [15 x i8] c"Echo message: \00"
@.str.8 = [16 x i8] c"recv() failuer\0A\00"
@str = [24 x i8] c"please input a message!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = alloca [1024 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = load i32, i32* @IPPROTO_TCP
%20 = tail call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 49152)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = call i32 @inet_addr(i8* %16)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @connect(i32 %20, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %14
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %14
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%39 = call i32 @strlen(i8* %7)
%40 = call i32 @send(i32 %20, i8* %7, i32 %39, i32 0)
%41 = icmp eq i32 %40, %39
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %35
%47 = call i32 @recv(i32 %20, i8* %8, i32 1024, i32 0)
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = zext i32 %47 to i64
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @puts(i8* %8)
br label %60
54: ; preds = %46
%55 = icmp slt i32 %47, 0
br i1 %55, label %56, label %60
56: ; preds = %54
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54, %49
%61 = call i32 @putchar(i32 10)
%62 = call i32 @close(i32 %20)
ret i32 0
}