#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_adr;
typedef int /*<<< orphan*/ message;
typedef int /*<<< orphan*/ from_adr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  char message[30];
  int str_len;
  socklen_t adr_sz;
  struct sockaddr_in serv_adr, from_adr;
  if (argc != 3) {
    printf("Usage : %s <IP> <port> \n", argv[0]);
    exit(1);
  }
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  if (sock == -1) {
    error_handling("socket() error");
  }
  memset(&serv_adr, 0, sizeof(serv_adr));
  serv_adr.sin_family = AF_INET;
  serv_adr.sin_addr.s_addr = inet_addr(argv[1]);
  serv_adr.sin_port = htons(atoi(argv[2]));
  while (1) {
    fputs("Insert message(q to quit)", stdout);
    fgets(message, sizeof(message), stdin);
    if (!strcmp(message, "q\n") || !strcmp(message, "Q\n"))
      break;
    sendto(sock, message, strlen(message), 0, (struct sockaddr *)&serv_adr,
           sizeof(serv_adr));
    adr_sz = sizeof(from_adr);
    str_len =
        recvfrom(sock, message, 30, 0, (struct sockaddr *)&serv_adr, &adr_sz);
    message[str_len] = 0;
    printf("Message from server: %s", message);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1230 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1262 <main+0x72>
lea    0xdbc(%rip),%rdi
call   10d0 <error_handling@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    0xd73(%rip),%rdi
call   1060 <fputs@plt>
lea    -0x40(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   10a0 <fgets@plt>
lea    -0x40(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
je     1303 <main+0x113>
lea    -0x40(%rbp),%rdi
lea    0xd50(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
jne    1308 <main+0x118>
jmp    137c <main+0x18c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x74(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    -0x58(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
movl   $0xc,-0x48(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x58(%rbp),%r8
mov    $0x1e,%edx
xor    %ecx,%ecx
lea    -0x48(%rbp),%r9
call   10e0 <recvfrom@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rsi
lea    0xcd6(%rip),%rdi
call   1050 <printf@plt>
jmp    12a5 <main+0xb5>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1391 <main+0x1b1>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1226 <main+0x46>
lea    0xdf8(%rip),%rdi
call   10c0 <error_handling@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    0xdb3(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
mov    $0x1e,%esi
call   10a0 <fgets@plt>
mov    $0xa71,%ecx
mov    0x20(%rsp),%eax
xor    %ecx,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
je     1379 <main+0x199>
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xd87(%rip),%r12
lea    0xd60(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp),%eax
mov    $0xa51,%ecx
xor    %ecx,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
je     1379 <main+0x199>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10d0 <recvfrom@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1060 <fputs@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   10a0 <fgets@plt>
mov    0x20(%rsp),%eax
mov    $0xa71,%ecx
xor    %ecx,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
jne    12d0 <main+0xf0>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xc65(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage : %s <IP> <port> \0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@.str.2 = [26 x i8] c"Insert message(q to quit)\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.3 = [3 x i8] c"q\0A\00"
@.str.4 = [3 x i8] c"Q\0A\00"
@.str.5 = [24 x i8] c"Message from server: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
%29 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @inet_addr(i8* %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = call i32 @htons(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %42, i32* %43
br label %44
44: ; preds = %28, %58
%45 = load i32, i32* @stdout
%46 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%48 = load i32, i32* @stdin
%49 = call i32 @fgets(i8* %47, i32 30, i32 %48)
%50 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %53, %44
br label %74
58: ; preds = %53
%59 = load i32, i32* %6
%60 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%61 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%64 = call i32 @sendto(i32 %59, i8* %60, i32 %62, i32 0, %struct.sockaddr* %63, i32 12)
store i32 12, i32* %9
%65 = load i32, i32* %6
%66 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%67 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%68 = call i32 @recvfrom(i32 %65, i8* %66, i32 30, i32 0, %struct.sockaddr* %67, i32* %9)
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 %70
store i8 0, i8* %71
%72 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %72)
br label %44
74: ; preds = %57
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage : %s <IP> <port> \0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@.str.2 = [26 x i8] c"Insert message(q to quit)\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.3 = [3 x i8] c"q\0A\00"
@.str.4 = [3 x i8] c"Q\0A\00"
@.str.5 = [24 x i8] c"Message from server: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @error_handling(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 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @inet_addr(i8* %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* @stdout
%35 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %6, i32 30, i32 %36)
%38 = call i32 @bcmp(i8* dereferenceable(3) %6, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%39 = icmp eq i32 %38, 0
br i1 %39, label %58, label %40
40: ; preds = %21
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %42
42: ; preds = %40, %45
%43 = call i32 @bcmp(i8* dereferenceable(3) %6, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3)
%44 = icmp eq i32 %43, 0
br i1 %44, label %58, label %45
45: ; preds = %42
%46 = call i32 @strlen(i8* %6)
%47 = call i32 @sendto(i32 %17, i8* %6, i32 %46, i32 0, %struct.sockaddr* %41, i32 12)
store i32 12, i32* %4
%48 = call i32 @recvfrom(i32 %17, i8* %6, i32 30, i32 0, %struct.sockaddr* %41, i32* %4)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%52 = load i32, i32* @stdout
%53 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %6, i32 30, i32 %54)
%56 = call i32 @bcmp(i8* dereferenceable(3) %6, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %42
58: ; preds = %42, %45, %21
%59 = call i32 @close(i32 %17)
ret i32 0
}