#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 dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int getaddrinfo(char *, char *, int /*<<< orphan*/ *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main() {
  int sock = socket(PF_INET, SOCK_DGRAM, 0);
  struct addrinfo *first_info;
  struct addrinfo hints;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  int r = getaddrinfo("localhost", "4242", NULL, &first_info);
  if (r == 0) {
    if (first_info != NULL) {
      struct sockaddr *saddr = first_info->ai_addr;
      char tampon[100];
      int i = 0;
      for (i = 0; i <= 10; i++) {
        strcpy(tampon, "MESSAGE ");
        char entier[3];
        sprintf(entier, "%d", i);
        strcat(tampon, entier);
        sendto(sock, tampon, strlen(tampon), 0, saddr,
               (socklen_t)sizeof(struct sockaddr_in));
      }
    }
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe13(%rip),%rdi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12e5 <main+0x155>
cmpq   $0x0,-0x10(%rbp)
je     12e0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa4(%rbp)
cmpl   $0xa,-0xa4(%rbp)
jg     12db <main+0x14b>
lea    -0xa0(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa7(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xdac(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa7(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
mov    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1060 <sendto@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1238 <main+0xa8>
jmp    12e0 <main+0x150>
jmp    12e5 <main+0x155>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xe18(%rip),%rdi
lea    0xe1b(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
jne    126f <main+0xdf>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     126f <main+0xdf>
mov    (%rax),%r12
xor    %ebp,%ebp
lea    0x20(%rsp),%rbx
lea    0xdfe(%rip),%r13
lea    0x5(%rsp),%r15
nop
mov    %rbx,%rdi
lea    0xde5(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x4,%r9d
call   1060 <sendto@plt>
add    $0x1,%ebp
cmp    $0xb,%ebp
jne    1220 <main+0x90>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { %struct.sockaddr*, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [9 x i8] c"MESSAGE \00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca [3 x i8]
store i32 0, i32* %1
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 16)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_DGRAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %3)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %51
21: ; preds = %0
%22 = load %struct.addrinfo*, %struct.addrinfo** %3
%23 = icmp ne %struct.addrinfo* %22, null
br i1 %23, label %24, label %50
24: ; preds = %21
%25 = load %struct.addrinfo*, %struct.addrinfo** %3
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i32 0, i32 0
%27 = load %struct.sockaddr*, %struct.sockaddr** %26
store %struct.sockaddr* %27, %struct.sockaddr** %6
store i32 0, i32* %8
store i32 0, i32* %8
br label %28
28: ; preds = %46, %24
%29 = load i32, i32* %8
%30 = icmp sle i32 %29, 10
br i1 %30, label %31, label %49
31: ; preds = %28
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%35 = load i32, i32* %8
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%39 = call i32 @strcat(i8* %37, i8* %38)
%40 = load i32, i32* %2
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = load %struct.sockaddr*, %struct.sockaddr** %6
%45 = call i32 @sendto(i32 %40, i8* %41, i32 %43, i32 0, %struct.sockaddr* %44, i32 4)
br label %46
46: ; preds = %31
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %28
49: ; preds = %28
br label %50
50: ; preds = %49, %21
br label %51
51: ; preds = %50, %0
%52 = load i32, i32* %2
%53 = call i32 @close(i32 %52)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.sockaddr*, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [9 x i8] c"MESSAGE \00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca %struct.addrinfo*
%2 = alloca %struct.addrinfo
%3 = alloca [100 x i8]
%4 = alloca [3 x i8]
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast %struct.addrinfo** %1 to i8*
%9 = bitcast %struct.addrinfo* %2 to i8*
%10 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 16)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_DGRAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %1)
%16 = icmp eq i32 %15, 0
%17 = load %struct.addrinfo*, %struct.addrinfo** %1
%18 = icmp ne %struct.addrinfo* %17, null
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %35
20: ; preds = %0
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 0
%22 = load %struct.sockaddr*, %struct.sockaddr** %21
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
br label %25
25: ; preds = %20, %25
%26 = phi i32 [ 0, %20 ], [ %32, %25 ]
%27 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%29 = call i32 @strcat(i8* %23, i8* %24)
%30 = call i32 @strlen(i8* %23)
%31 = call i32 @sendto(i32 %7, i8* %23, i32 %30, i32 0, %struct.sockaddr* %22, i32 4)
%32 = add nuw nsw i32 %26, 1
%33 = icmp eq i32 %32, 11
br i1 %33, label %34, label %25
34: ; preds = %25
br label %35
35: ; preds = %34, %0
%36 = call i32 @close(i32 %7)
ret i32 0
}