#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 *)&from_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    0xdba(%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    0xd71(%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    -0x68(%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    $0x58,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1393 <main+0x1b3>
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    0xdf6(%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    0xdb1(%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     137b <main+0x19b>
lea    0x20(%rsp),%rbx
lea    0x48(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xd87(%rip),%r13
lea    0xd5e(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp),%eax
mov    $0xa51,%ecx
xor    %ecx,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
je     137b <main+0x19b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%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    %r15,%r8
mov    %r12,%r9
call   10d0 <recvfrom@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <fputs@plt>
mov    0x2c8d(%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    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xc63(%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 = [23 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 = [28 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 ([23 x i8], [23 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 ([28 x i8], [28 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* %11 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 = [23 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 = [28 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 = alloca %struct.sockaddr_in
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
%34 = call i32 @htons(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %34, i32* %35
%36 = load i32, i32* @stdout
%37 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %7, i32 30, i32 %38)
%40 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%41 = icmp eq i32 %40, 0
br i1 %41, label %61, label %42
42: ; preds = %23
%43 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%44 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %45
45: ; preds = %42, %48
%46 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3)
%47 = icmp eq i32 %46, 0
br i1 %47, label %61, label %48
48: ; preds = %45
%49 = call i32 @strlen(i8* %7)
%50 = call i32 @sendto(i32 %19, i8* %7, i32 %49, i32 0, %struct.sockaddr* %43, i32 12)
store i32 12, i32* %4
%51 = call i32 @recvfrom(i32 %19, i8* %7, i32 30, i32 0, %struct.sockaddr* %44, i32* %4)
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
%54 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%55 = load i32, i32* @stdout
%56 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @stdin
%58 = call i32 @fgets(i8* %7, i32 30, i32 %57)
%59 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %45
61: ; preds = %45, %48, %23
%62 = call i32 @close(i32 %19)
ret i32 0
}