#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servidor;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ 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*/ sprintf(char *, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_in servidor;
  int s, i;
  socklen_t slen = sizeof(servidor);
  char buf[512];
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
    printf("ERRO AO CRIAR SOCKET\n");
    return 1;
  }
  memset((char *)&servidor, 0, sizeof(servidor));
  servidor.sin_family = AF_INET;
  servidor.sin_port = htons(4444);
  printf("Setando porta: %d\n", 4444);
  if (inet_aton("127.0.0.1", &servidor.sin_addr) == 0) {
    printf("ERRO AO TRANSFORMAR ENDEREÇO\n");
    return 1;
  }
  for (i = 0; i < 10; i++) {
    printf("Enviando pacote %d\n", i);
    sprintf(buf, "Este é o pacote #%d\n", i);
    if (sendto(s, buf, 512, 0, (struct sockaddr *)&servidor, slen) == -1) {
      printf("ERRO AO ENVIAR PACOTE\n");
      return 1;
    }
  }
  recvfrom(s, buf, 512, 0, (struct sockaddr *)&servidor, &slen);
  printf("Pacote recebido de %s:%d\nDado: %s\n", inet_ntoa(servidor.sin_addr),
         ntohs(servidor.sin_port), buf);
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <main+0x66>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1c8>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x115c,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    0xdd0(%rip),%rdi
mov    $0x115c,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
lea    0xdc8(%rip),%rdi
call   1090 <inet_aton@plt>
cmp    $0x0,%rax
jne    128a <main+0xda>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1c8>
movl   $0x0,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    1316 <main+0x166>
mov    -0x28(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xda9(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x24(%rbp),%edi
lea    -0x230(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    $0x200,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1303 <main+0x153>
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1c8>
jmp    1308 <main+0x158>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1291 <main+0xe1>
mov    -0x24(%rbp),%edi
lea    -0x230(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x238(%rbp)
mov    -0x20(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
lea    -0x230(%rbp),%rcx
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2e08(%rip),%rbx
mov    (%rbx),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     1306 <main+0x146>
mov    %eax,%r13d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x115c,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
lea    0xdd2(%rip),%rdi
mov    $0x115c,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rsi
lea    0xdcd(%rip),%rdi
call   10a0 <inet_aton@plt>
test   %rax,%rax
je     130f <main+0x14f>
lea    0xdc2(%rip),%r14
lea    0xdcf(%rip),%r15
lea    0x10(%rsp),%rbp
mov    %rsp,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10d0 <sprintf@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     1318 <main+0x158>
add    $0x1,%ebx
cmp    $0xa,%ebx
jne    1270 <main+0xb0>
lea    0x10(%rsp),%r14
xor    %ebp,%ebp
mov    %rsp,%r8
lea    0xc(%rsp),%r9
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
mov    0x4(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbx
mov    (%rsp),%edi
call   10c0 <ntohs@plt>
lea    0xd5a(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13d,%edi
call   1090 <close@plt>
jmp    1329 <main+0x169>
lea    0xd91(%rip),%rdi
jmp    131f <main+0x15f>
lea    0xd6a(%rip),%rdi
jmp    131f <main+0x15f>
lea    0xd4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [22 x i8] c"ERRO AO CRIAR SOCKET\0A\00"
@.str.1 = [19 x i8] c"Setando porta: %d\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [31 x i8] c"ERRO AO TRANSFORMAR ENDERE\C3\87O\0A\00"
@.str.4 = [20 x i8] c"Enviando pacote %d\0A\00"
@.str.5 = [22 x i8] c"Este \C3\A9 o pacote #%d\0A\00"
@.str.6 = [23 x i8] c"ERRO AO ENVIAR PACOTE\0A\00"
@.str.7 = [35 x i8] c"Pacote recebido de %s:%d\0ADado: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %9
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = load i32, i32* @IPPROTO_UDP
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %68
18: ; preds = %2
%19 = bitcast %struct.sockaddr_in* %6 to i8*
%20 = call i32 @memset(i8* %19, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 4444)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %23, i32* %24
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 4444)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%27 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %68
31: ; preds = %18
store i32 0, i32* %8
br label %32
32: ; preds = %50, %31
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %53
35: ; preds = %32
%36 = load i32, i32* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%39 = load i32, i32* %8
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %7
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%43 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%44 = load i32, i32* %9
%45 = call i32 @sendto(i32 %41, i8* %42, i32 512, i32 0, %struct.sockaddr* %43, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %35
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %68
49: ; preds = %35
br label %50
50: ; preds = %49
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %32
53: ; preds = %32
%54 = load i32, i32* %7
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%56 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%57 = call i32 @recvfrom(i32 %54, i8* %55, i32 512, i32 0, %struct.sockaddr* %56, i32* %9)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i8* @inet_ntoa(i32 %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @ntohs(i32 %62)
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %60, i32 %63, i8* %64)
%66 = load i32, i32* %7
%67 = call i32 @close(i32 %66)
store i32 0, i32* %3
br label %68
68: ; preds = %53, %47, %29, %16
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [19 x i8] c"Setando porta: %d\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [20 x i8] c"Enviando pacote %d\0A\00"
@.str.5 = [22 x i8] c"Este \C3\A9 o pacote #%d\0A\00"
@.str.7 = [35 x i8] c"Pacote recebido de %s:%d\0ADado: %s\0A\00"
@str = [22 x i8] c"ERRO AO ENVIAR PACOTE\00"
@str.8 = [30 x i8] c"ERRO AO TRANSFORMAR ENDERE\C3\87O\00"
@str.9 = [21 x i8] c"ERRO AO CRIAR SOCKET\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
br label %49
16: ; preds = %2
%17 = call i32 @memset(i8* %6, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 4444)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %20, i32* %21
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 4444)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%24 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %16
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %33
28: ; preds = %16
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.8, i64 0, i64 0))
br label %49
30: ; preds = %33
%31 = add nuw nsw i32 %34, 1
%32 = icmp eq i32 %31, 10
br i1 %32, label %41, label %33
33: ; preds = %26, %30
%34 = phi i32 [ 0, %26 ], [ %31, %30 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%37 = call i32 @sendto(i32 %12, i8* %8, i32 512, i32 0, %struct.sockaddr* %27, i32 12)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %30
39: ; preds = %33
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %49
41: ; preds = %30
%42 = call i32 @recvfrom(i32 %12, i8* %8, i32 512, i32 0, %struct.sockaddr* %27, i32* %4)
%43 = load i32, i32* %23
%44 = call i8* @inet_ntoa(i32 %43)
%45 = load i32, i32* %21
%46 = call i32 @ntohs(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %44, i32 %46, i8* %8)
%48 = call i32 @close(i32 %12)
br label %49
49: ; preds = %41, %39, %28, %14
%50 = phi i32 [ 1, %14 ], [ 1, %28 ], [ 1, %39 ], [ 0, %41 ]
ret i32 %50
}