#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*/ socklen_t;
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int read(int, char *, int);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd;
  int len;
  char buffer[1024];
  socklen_t addr_len;
  struct sockaddr_in serveraddr;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <Server IP address>\neg. $%s 127.0.0.1\n",
            argv[0], argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    error("socket() error");
  bzero(&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_port = htons(9669);
  if (inet_pton(AF_INET, argv[1], &serveraddr.sin_addr) <= 0)
    error("inet_pton() error");
  while (fgets(buffer, 1024, stdin) != NULL) {
    sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr *)&serveraddr,
           sizeof(serveraddr));
    if ((len = read(sockfd, buffer, 1024)) < 0)
      error("read() error");
    buffer[len] = 0;
    fputs(buffer, stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1214 <main+0x54>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdff(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1245 <main+0x85>
lea    0xdf1(%rip),%rdi
call   10b0 <error@plt>
lea    -0x430(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    $0x25c5,%edi
call   1040 <htons@plt>
mov    %eax,-0x42c(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x430(%rbp),%rdx
call   10a0 <inet_pton@plt>
cmp    $0x0,%rax
jg     12a8 <main+0xe8>
lea    0xd9d(%rip),%rdi
call   10b0 <error@plt>
jmp    12ad <main+0xed>
lea    -0x420(%rbp),%rdi
mov    0x2d25(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1369 <main+0x1a9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
lea    -0x430(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1343 <main+0x183>
lea    0xd14(%rip),%rdi
call   10b0 <error@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    0x2c5b(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    12ad <main+0xed>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1301 <main+0x141>
mov    0x2e04(%rip),%rbx
mov    (%rbx),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1209 <main+0x49>
lea    0xe2d(%rip),%rdi
call   10b0 <error@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x25c5,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    0x8(%r14),%rsi
mov    %rbp,%rdx
call   10a0 <inet_pton@plt>
test   %rax,%rax
jg     124c <main+0x8c>
lea    0xdf9(%rip),%rdi
call   10b0 <error@plt>
mov    0x2d8d(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12ed <main+0x12d>
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
mov    0x2d3a(%rip),%r15
jmp    12a9 <main+0xe9>
movslq %ebp,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12ed <main+0x12d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1280 <main+0xc0>
lea    0xd6c(%rip),%rdi
call   10b0 <error@plt>
jmp    1280 <main+0xc0>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rcx
lea    0xcec(%rip),%rsi
mov    %rcx,%rdx
call   1090 <fprintf@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"usage: %s <Server IP address>\0Aeg. $%s 127.0.0.1\0A\00"
@EXIT_FAILURE = global i32 0
@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 = [13 x i8] c"read() error\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 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 %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 9669)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%31 = call i64 @inet_pton(i32 %27, i8* %29, i32* %30)
%32 = icmp slt i64 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %21
%34 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %21
%36 = load i32, i32* @stdin
%37 = call i32* @fgets(i8* %5, i32 1024, i32 %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %56, label %39
39: ; preds = %35
%40 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %41
41: ; preds = %39, %48
%42 = call i32 @strlen(i8* %5)
%43 = call i32 @sendto(i32 %17, i8* %5, i32 %42, i32 0, %struct.sockaddr* %40, i32 12)
%44 = call i32 @read(i32 %17, i8* %5, i32 1024)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = sext i32 %44 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* @stdout
%52 = call i32 @fputs(i8* %5, i32 %51)
%53 = load i32, i32* @stdin
%54 = call i32* @fgets(i8* %5, i32 1024, i32 %53)
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %41
56: ; preds = %48, %35
ret i32 0
}