#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 /*<<< 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*/ 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, "\n\tSERVER: ERRO: porta nÃo informada\n");
    exit(0);
  }
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    error("\n\tSERVER:-error: Opening socket\n\t");
  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("\nSERVER:-error: binding\n");
  fromlen = sizeof(struct sockaddr_in);
  while (1) {
    printf("\n\t teste antes de rec from\n");
    n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen);
    printf("\n\tteste depois do rec from\n");
    if (n < 0)
      error("\n\tSERVER:- error: received from\n\n");
    write(1, "\n\tSERVER: Datagrama: ", 21);
    write(1, buf, n);
    n = sendto(sock, "\n\tSERVER: MSG recebida ! \n\n", 30, 0,
               (struct sockaddr *)&from, fromlen);
    if (n < 0)
      error("\n\tSERVER: send to\n\n");
  }
}


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    11ff <main+0x3f>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1231 <main+0x71>
lea    0xdfa(%rip),%rdi
call   10a0 <error@plt>
movl   $0xc,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   10b0 <bzero@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <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   1090 <bind@plt>
cmp    $0x0,%rax
jge    1298 <main+0xd8>
lea    0xdb5(%rip),%rdi
call   10a0 <error@plt>
movl   $0xc,-0x1c(%rbp)
lea    0xdbb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
lea    0xdaa(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jge    12ee <main+0x12e>
lea    0xdb0(%rip),%rdi
call   10a0 <error@plt>
mov    $0x1,%edi
lea    0xdc1(%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    0xda7(%rip),%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    134f <main+0x18f>
lea    0xda3(%rip),%rdi
call   10a0 <error@plt>
jmp    129f <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    1326 <main+0x166>
mov    %rsi,%rbp
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1208 <main+0x48>
lea    0xe23(%rip),%rdi
call   10a0 <error@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
jns    1268 <main+0xa8>
lea    0xde5(%rip),%rdi
call   10a0 <error@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%r15
lea    0x20(%rsp),%r12
lea    0xe02(%rip),%r14
lea    0xe11(%rip),%r13
nopl   0x0(%rax,%rax,1)
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r12,%r8
lea    0xc(%rsp),%r9
call   1080 <recvfrom@plt>
mov    %eax,%ebp
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jns    12d3 <main+0x113>
lea    0xd93(%rip),%rdi
call   10a0 <error@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x15,%edx
call   1040 <write@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1060 <sendto@plt>
test   %eax,%eax
jns    1290 <main+0xd0>
lea    0xd99(%rip),%rdi
call   10a0 <error@plt>
jmp    1290 <main+0xd0>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10d0 <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 = [38 x i8] c"\0A\09SERVER: ERRO: porta n\C3\83o informada\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [34 x i8] c"\0A\09SERVER:-error: Opening socket\0A\09\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [25 x i8] c"\0ASERVER:-error: binding\0A\00"
@.str.3 = [28 x i8] c"\0A\09 teste antes de rec from\0A\00"
@.str.4 = [28 x i8] c"\0A\09teste depois do rec from\0A\00"
@.str.5 = [34 x i8] c"\0A\09SERVER:- error: received from\0A\0A\00"
@.str.6 = [22 x i8] c"\0A\09SERVER: Datagrama: \00"
@.str.7 = [28 x i8] c"\0A\09SERVER: MSG recebida ! \0A\0A\00"
@.str.8 = [20 x i8] c"\0A\09SERVER: send to\0A\0A\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 ([38 x i8], [38 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 ([34 x i8], [34 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 ([25 x i8], [25 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, %73
%50 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* %6
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %51, i8* %52, i32 1024, i32 0, %struct.sockaddr* %53, i32* %8)
store i32 %54, i32* %9
%55 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %9
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %49
%61 = call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 21)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%63 = load i32, i32* %9
%64 = call i32 @write(i32 1, i8* %62, i32 %63)
%65 = load i32, i32* %6
%66 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%67 = load i32, i32* %8
%68 = call i32 @sendto(i32 %65, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 30, i32 0, %struct.sockaddr* %66, i32 %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %60
%72 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %71, %60
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 = [38 x i8] c"\0A\09SERVER: ERRO: porta n\C3\83o informada\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [34 x i8] c"\0A\09SERVER:-error: Opening socket\0A\09\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [25 x i8] c"\0ASERVER:-error: binding\0A\00"
@.str.5 = [34 x i8] c"\0A\09SERVER:- error: received from\0A\0A\00"
@.str.6 = [22 x i8] c"\0A\09SERVER: Datagrama: \00"
@.str.7 = [28 x i8] c"\0A\09SERVER: MSG recebida ! \0A\0A\00"
@.str.8 = [20 x i8] c"\0A\09SERVER: send to\0A\0A\00"
@str = [27 x i8] c"\0A\09 teste antes de rec from\00"
@str.9 = [27 x i8] c"\0A\09teste depois do rec from\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 ([38 x i8], [38 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 ([34 x i8], [34 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 ([25 x i8], [25 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 = %56, %39
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%43 = call i32 @recvfrom(i32 %19, i8* %10, i32 1024, i32 0, %struct.sockaddr* %40, i32* %3)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
%45 = icmp slt i32 %43, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 21)
%50 = call i32 @write(i32 1, i8* %10, i32 %43)
%51 = load i32, i32* %3
%52 = call i32 @sendto(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 30, i32 0, %struct.sockaddr* %40, i32 %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
br label %41
}