#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 /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
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*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sock, length, fromlen, n;
  struct sockaddr_in server;
  struct sockaddr_in from;
  char buf[1024];
  if (argc < 2) {
    fprintf(stderr, "ERRO: porta nÃo informada\n");
    exit(0);
  }
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    error("Opening socket");
  length = sizeof(server);
  bzero(&server, length);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(atoi(argv[1]));
  if (bind(sock, (struct sockaddr *)&server, length) < 0)
    error("binding");
  fromlen = sizeof(struct sockaddr_in);
  while (1) {
    n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen);
    if (n < 0)
      error("recvfrom");
    write(1, "Datagrama: ", 21);
    write(1, buf, n);
    n = sendto(sock, "MSG recebida ! \n", 17, 0, (struct sockaddr *)&from,
               fromlen);
    if (n < 0)
      error("sendto");
  }
}


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)
jge    11ef <main+0x3f>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1221 <main+0x71>
lea    0xe00(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   10a0 <bzero@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1288 <main+0xd8>
lea    0xda8(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12c6 <main+0x116>
lea    0xd72(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
lea    0xd6a(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
lea    -0x440(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%r8
mov    -0x1c(%rbp),%r9d
lea    0xd46(%rip),%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
call   1050 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1327 <main+0x177>
lea    0xd37(%rip),%rdi
call   1090 <error@plt>
jmp    128f <main+0xdf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
cmp    $0x1,%edi
jle    12f9 <main+0x149>
mov    %rsi,%rbp
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f8 <main+0x48>
lea    0xe29(%rip),%rdi
call   1090 <error@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    1258 <main+0xa8>
lea    0xdd8(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xdcb(%rip),%rbp
lea    0xdd0(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
lea    0xc(%rsp),%r9
call   1070 <recvfrom@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    12ac <main+0xfc>
lea    0xd8c(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1050 <sendto@plt>
test   %eax,%eax
jns    1280 <main+0xd0>
lea    0xd67(%rip),%rdi
call   1090 <error@plt>
jmp    1280 <main+0xd0>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xcf7(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"ERRO: porta n\C3\83o informada\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"Opening socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [8 x i8] c"binding\00"
@.str.3 = [9 x i8] c"recvfrom\00"
@.str.4 = [12 x i8] c"Datagrama: \00"
@.str.5 = [17 x i8] c"MSG recebida ! \0A\00"
@.str.6 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
store i32 12, i32* %7
%28 = load i32, i32* %7
%29 = call i32 @bzero(%struct.sockaddr_in* %10, i32 %28)
%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 i32, i32* @INADDR_ANY
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%43 = load i32, i32* %7
%44 = call i64 @bind(i32 %41, %struct.sockaddr* %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %27
%47 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %27
store i32 12, i32* %8
br label %49
49: ; preds = %48, %71
%50 = load i32, i32* %6
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%52 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%53 = call i32 @recvfrom(i32 %50, i8* %51, i32 1024, i32 0, %struct.sockaddr* %52, i32* %8)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %49
%57 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %49
%59 = call i32 @write(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 21)
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%61 = load i32, i32* %9
%62 = call i32 @write(i32 1, i8* %60, i32 %61)
%63 = load i32, i32* %6
%64 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%65 = load i32, i32* %8
%66 = call i32 @sendto(i32 %63, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 17, i32 0, %struct.sockaddr* %64, i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %58
%70 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %71
71: ; preds = %69, %58
br label %49
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"ERRO: porta n\C3\83o informada\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"Opening socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [8 x i8] c"binding\00"
@.str.3 = [9 x i8] c"recvfrom\00"
@.str.4 = [12 x i8] c"Datagrama: \00"
@.str.5 = [17 x i8] c"MSG recebida ! \0A\00"
@.str.6 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
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 slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error(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 @bzero(%struct.sockaddr_in* %4, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = tail call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %19, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %23
store i32 12, i32* %3
%40 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %41
41: ; preds = %54, %39
%42 = call i32 @recvfrom(i32 %19, i8* %10, i32 1024, i32 0, %struct.sockaddr* %40, i32* %3)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = call i32 @write(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 21)
%48 = call i32 @write(i32 1, i8* %10, i32 %42)
%49 = load i32, i32* %3
%50 = call i32 @sendto(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 17, i32 0, %struct.sockaddr* %40, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %46
br label %41
}