#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 */
typedef int u_short;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ mesaj;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(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;
int strlen(char *);
main() {
  int sd;
  struct sockaddr_in server;
  char mesaj[100];
  u_short lh, ln;
  int i;
  sd = socket(AF_INET, SOCK_DGRAM, 0);
  printf("socket %d\n", sd);
  memset((char *)&server, 0, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("172.30.112.241");
  server.sin_port = htons(12345);
  lh = strlen(mesaj);
  ln = htons(lh);
  int lung = sizeof(server);
  while (1) {
    printf("> ");
    fgets(mesaj, sizeof(mesaj), stdin);
    i = sendto(sd, (char *)&mesaj, sizeof(mesaj), 0, (struct sockaddr *)&server,
               sizeof(server));
    i = recvfrom(sd, (char *)&mesaj, sizeof(mesaj), 0,
                 (struct sockaddr *)&server, &lung);
    printf("< %s\n", mesaj);
  }
  close(sd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    0xe19(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x10(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x88(%rbp)
movl   $0x10,-0x90(%rbp)
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x90(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1232 <main+0xa2>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2e40(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
lea    0xe1e(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x18(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <htons@plt>
movl   $0x10,0xc(%rsp)
mov    0x2db8(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xde9(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdd3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r12,%r9
call   10a0 <recvfrom@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1240 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [11 x i8] c"socket %d\0A\00"
@.str.1 = [15 x i8] c"172.30.112.241\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"< %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @memset(i8* %14, i32 0, i32 16)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = call i8* @htons(i32 12345)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i8* %21, i8** %22
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = call i8* @htons(i32 %25)
%27 = ptrtoint i8* %26 to i32
store i32 %27, i32* %6
store i32 16, i32* %8
br label %28
28: ; preds = %0, %28
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %30, i32 100, i32 %31)
%33 = load i32, i32* %2
%34 = bitcast [100 x i8]* %4 to i8*
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i32 @sendto(i32 %33, i8* %34, i32 100, i32 0, %struct.sockaddr* %35, i32 16)
store i32 %36, i32* %7
%37 = load i32, i32* %2
%38 = bitcast [100 x i8]* %4 to i8*
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i32 @recvfrom(i32 %37, i8* %38, i32 100, i32 0, %struct.sockaddr* %39, i32* %8)
store i32 %40, i32* %7
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [11 x i8] c"socket %d\0A\00"
@.str.1 = [15 x i8] c"172.30.112.241\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"< %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @memset(i8* %4, i32 0, i32 16)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i8* @htons(i32 12345)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %15, i8** %16
%17 = call i32 @strlen(i8* %5)
%18 = call i8* @htons(i32 %17)
%19 = bitcast i32* %3 to i8*
store i32 16, i32* %3
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %21
21: ; preds = %21, %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %5, i32 100, i32 %23)
%25 = call i32 @sendto(i32 %8, i8* %5, i32 100, i32 0, %struct.sockaddr* %20, i32 16)
%26 = call i32 @recvfrom(i32 %8, i8* %5, i32 100, i32 0, %struct.sockaddr* %20, i32* %3)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %21
}