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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in server_addr;
  socklen_t server_addr_len = sizeof(struct sockaddr);
  int connfd;
  char buf[1024 + 1];
  int n;
  if (argc != 3) {
    perror("Please use 3 args\n");
    exit(1);
  }
  connfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(atoi(argv[2]));
  if (inet_aton(argv[1], &server_addr.sin_addr) == 0) {
    perror("inet_aton.");
    exit(1);
  }
  while (1) {
    memset(buf, 0, 1024 + 1);
    printf("You would say :");
    fgets(buf, sizeof(buf), stdin);
    n = sendto(connfd, buf, sizeof(buf), 0, (struct sockaddr *)&server_addr,
               sizeof(server_addr));
    if (n == -1) {
      perror("Send to Server");
      exit(1);
    }
    if (strcmp(buf, "exit\n") == 0) {
      break;
    }
    n = recvfrom(connfd, buf, 1024, 0, (struct sockaddr *)&server_addr,
                 &server_addr_len);
    if (n == -1) {
      perror("Receive from Server");
      exit(1);
    } else {
      buf[n] = '\0';
      printf("Server send to you: %s\n", buf);
    }
  }
  if (close(connfd) == -1) {
    perror("Close");
    exit(1);
  }
  puts("UDP Client has been closed");
  return 0;
}


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)
movl   $0x4,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1230 <main+0x40>
lea    0xddf(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <inet_aton@plt>
cmp    $0x0,%rax
jne    12ae <main+0xbe>
lea    0xd74(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12b3 <main+0xc3>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1060 <memset@plt>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
mov    $0x401,%esi
call   1090 <fgets@plt>
mov    -0x28(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x401,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    1337 <main+0x147>
lea    0xd06(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x430(%rbp),%rdi
lea    0xcf8(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1359 <main+0x169>
jmp    13c9 <main+0x1d9>
mov    -0x28(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    13a0 <main+0x1b0>
lea    0xcb2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b3 <main+0xc3>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    13f0 <main+0x200>
lea    0xc8e(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc7e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%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    $0x428,%rsp
movl   $0x4,0xc(%rsp)
cmp    $0x3,%edi
jne    1372 <main+0x182>
mov    %rsi,%rbx
mov    0x2dcc(%rip),%r15
mov    (%r15),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   10b0 <inet_aton@plt>
test   %rax,%rax
je     137b <main+0x18b>
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xdb9(%rip),%r12
lea    0xc(%rsp),%r13
lea    0xdc7(%rip),%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1060 <memset@plt>
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x401,%esi
call   1090 <fgets@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x401,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
je     1353 <main+0x163>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1327 <main+0x137>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r13,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     135c <main+0x16c>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1290 <main+0xa0>
mov    %ebp,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     1384 <main+0x194>
lea    0xd3b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd4(%rip),%rdi
jmp    1363 <main+0x173>
lea    0xce0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc87(%rip),%rdi
jmp    1363 <main+0x173>
lea    0xc91(%rip),%rdi
jmp    1363 <main+0x173>
lea    0xce4(%rip),%rdi
jmp    1363 <main+0x173>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Please use 3 args\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [11 x i8] c"inet_aton.\00"
@.str.2 = [16 x i8] c"You would say :\00"
@stdin = global i32 0
@.str.3 = [15 x i8] c"Send to Server\00"
@.str.4 = [6 x i8] c"exit\0A\00"
@.str.5 = [20 x i8] c"Receive from Server\00"
@.str.6 = [24 x i8] c"Server send to you: %s\0A\00"
@.str.7 = [6 x i8] c"Close\00"
@.str.8 = [27 x i8] c"UDP Client has been closed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1025 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %8
%20 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%33 = call i64 @inet_aton(i8* %31, i32* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %16
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %16
br label %39
39: ; preds = %38, %76
%40 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 1025)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%43 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %43, i32 1025, i32 %44)
%46 = load i32, i32* %8
%47 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%48 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%49 = call i32 @sendto(i32 %46, i8* %47, i32 1025, i32 0, %struct.sockaddr* %48, i32 12)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %39
%53 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %39
%56 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
br label %77
60: ; preds = %55
%61 = load i32, i32* %8
%62 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%63 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%64 = call i32 @recvfrom(i32 %61, i8* %62, i32 1024, i32 0, %struct.sockaddr* %63, i32* %7)
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60
%71 = load i32, i32* %10
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 %72
store i8 0, i8* %73
%74 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %70
br label %39
77: ; preds = %59
%78 = load i32, i32* %8
%79 = call i32 @close(i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %77
%82 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %77
%85 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Please use 3 args\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [11 x i8] c"inet_aton.\00"
@.str.2 = [16 x i8] c"You would say :\00"
@stdin = global i32 0
@.str.3 = [15 x i8] c"Send to Server\00"
@.str.4 = [6 x i8] c"exit\0A\00"
@.str.5 = [20 x i8] c"Receive from Server\00"
@.str.6 = [24 x i8] c"Server send to you: %s\0A\00"
@.str.7 = [6 x i8] c"Close\00"
@.str.8 = [27 x i8] c"UDP Client has been closed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1025 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = tail call i32 @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%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_aton(i8* %26, i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %13
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %35
32: ; preds = %13
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %30, %54
%36 = call i32 @memset(i8* %8, i32 0, i32 1025)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %8, i32 1025, i32 %38)
%40 = call i32 @sendto(i32 %16, i8* %8, i32 1025, i32 0, %struct.sockaddr* %31, i32 12)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %35
%43 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %58, label %48
48: ; preds = %45
%49 = call i32 @recvfrom(i32 %16, i8* %8, i32 1024, i32 0, %struct.sockaddr* %31, i32* %4)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %48
%55 = sext i32 %49 to i64
%56 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 %55
store i8 0, i8* %56
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %35
58: ; preds = %45
%59 = call i32 @close(i32 %16)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %58
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}