#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*/ srvAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
scalar_t__ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  if (argc != 2)
    fprintf(stderr, "Usage: %s [Server IP]\n", argv[0]);
  int sockFd;
  if ((sockFd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    perror("socket() error");
  struct sockaddr_in srvAddr;
  bzero(&srvAddr, sizeof(srvAddr));
  srvAddr.sin_family = AF_INET;
  srvAddr.sin_port = htons(57345);
  if (inet_pton(AF_INET, argv[1], &srvAddr.sin_addr) <= 0)
    perror("inet_pton() error");
  char buf[4096];
  while (fgets(buf, 4096, stdin) != NULL) {
    if (!strcmp(buf, "\n"))
      break;
    if (sendto(sockFd, buf, strlen(buf) + 1, 0,
               (const struct sockaddr *)&srvAddr, sizeof(srvAddr)) < 0)
      perror("sendto() error");
    if (recvfrom(sockFd, buf, 4096, 0, NULL, NULL) < 0)
      perror("recvfrom() error");
    fputs(buf, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ff <main+0x3f>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1230 <main+0x70>
lea    0xdec(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xe001,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <inet_pton@plt>
cmp    $0x0,%rax
jg     1287 <main+0xc7>
lea    0xda4(%rip),%rdi
call   10c0 <perror@plt>
jmp    128c <main+0xcc>
lea    -0x1020(%rbp),%rdi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     137d <main+0x1bd>
lea    -0x1020(%rbp),%rdi
lea    0xd57(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12d1 <main+0x111>
jmp    137d <main+0x1bd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x102c(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x102c(%rbp),%edi
mov    -0x1028(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    132f <main+0x16f>
lea    0xd0e(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10b0 <recvfrom@plt>
cmp    $0x0,%rax
jge    1363 <main+0x1a3>
lea    0xce9(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2c4f(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    128c <main+0xcc>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     11e1 <main+0x31>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe24(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2e00(%rip),%r15
mov    (%r15),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1329 <main+0x179>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0xe001,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r15),%edi
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
jle    133a <main+0x18a>
mov    0x2d97(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1315 <main+0x165>
cmpw   $0xa,0x10(%rsp)
je     1315 <main+0x165>
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
lea    0xdc7(%rip),%r12
mov    0x2d39(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
js     12fd <main+0x14d>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
test   %rax,%rax
js     130b <main+0x15b>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1315 <main+0x165>
cmpw   $0xa,0x10(%rsp)
jne    1290 <main+0xe0>
jmp    1315 <main+0x165>
lea    0xd34(%rip),%rdi
call   10b0 <perror@plt>
jmp    12b6 <main+0x106>
mov    %r12,%rdi
call   10b0 <perror@plt>
jmp    12d2 <main+0x122>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce7(%rip),%rdi
call   10b0 <perror@plt>
jmp    1205 <main+0x55>
lea    0xce5(%rip),%rdi
call   10b0 <perror@plt>
jmp    1242 <main+0x92>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s [Server IP]\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [18 x i8] c"inet_pton() error\00"
@stdin = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [15 x i8] c"sendto() error\00"
@.str.5 = [17 x i8] c"recvfrom() error\00"
@stdout = 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
%8 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %11, %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @htons(i32 57345)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%35 = call i64 @inet_pton(i32 %30, i8* %33, i32* %34)
%36 = icmp sle i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %24
%38 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %24
br label %40
40: ; preds = %68, %39
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32* @fgets(i8* %41, i32 4096, i32 %42)
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %72
45: ; preds = %40
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
br label %72
50: ; preds = %45
%51 = load i32, i32* %6
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%54 = call i64 @strlen(i8* %53)
%55 = add nsw i64 %54, 1
%56 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%57 = call i64 @sendto(i32 %51, i8* %52, i64 %55, i32 0, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %50
%60 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %50
%62 = load i32, i32* %6
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%64 = call i64 @recvfrom(i32 %62, i8* %63, i32 4096, i32 0, i32* null, i32* null)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %61
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%70 = load i32, i32* @stdout
%71 = call i32 @fputs(i8* %69, i32 %70)
br label %40
72: ; preds = %49, %40
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s [Server IP]\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [18 x i8] c"inet_pton() error\00"
@stdin = global i32 0
@.str.4 = [15 x i8] c"sendto() error\00"
@.str.5 = [17 x i8] c"recvfrom() error\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6, %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 57345)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%28 = call i64 @inet_pton(i32 %24, i8* %26, i32* %27)
%29 = icmp slt i64 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %17
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32* @fgets(i8* %33, i32 4096, i32 %34)
%36 = icmp eq i32* %35, null
%37 = bitcast [4096 x i8]* %4 to i16*
%38 = load i16, i16* %37
%39 = icmp eq i16 %38, 10
%40 = select i1 %36, i1 true, i1 %39
br i1 %40, label %64, label %41
41: ; preds = %32
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %43
43: ; preds = %41, %55
%44 = call i64 @strlen(i8* %33)
%45 = add nsw i64 %44, 1
%46 = call i64 @sendto(i32 %13, i8* %33, i64 %45, i32 0, %struct.sockaddr* %42, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %43
%51 = call i64 @recvfrom(i32 %13, i8* %33, i32 4096, i32 0, i32* null, i32* null)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* @stdout
%57 = call i32 @fputs(i8* %33, i32 %56)
%58 = load i32, i32* @stdin
%59 = call i32* @fgets(i8* %33, i32 4096, i32 %58)
%60 = icmp eq i32* %59, null
%61 = load i16, i16* %37
%62 = icmp eq i16 %61, 10
%63 = select i1 %60, i1 true, i1 %62
br i1 %63, label %64, label %43
64: ; preds = %55, %32
ret i32 0
}