#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;
typedef int /*<<< orphan*/ ok;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(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 setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
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);
  int ok = 1;
  int r = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &ok, sizeof(ok));
  if (r != 0) {
    exit(1);
  }
  struct addrinfo *first_info;
  struct addrinfo hints;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  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    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1220 <main+0x70>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xdb1(%rip),%rdi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1347 <main+0x197>
cmpq   $0x0,-0x18(%rbp)
je     1342 <main+0x192>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa4(%rbp)
cmpl   $0xa,-0xa4(%rbp)
jg     133d <main+0x18d>
lea    -0xa0(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa7(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xd4a(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa7(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
mov    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1070 <sendto@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    129a <main+0xea>
jmp    1342 <main+0x192>
jmp    1347 <main+0x197>
mov    -0x8(%rbp),%edi
call   1080 <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    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r14d
movl   $0x1,(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %eax,%eax
jne    12eb <main+0x13b>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xdc6(%rip),%rdi
lea    0xdc9(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
jne    12cf <main+0x11f>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12cf <main+0x11f>
mov    (%rax),%r12
xor    %ebp,%ebp
lea    0x20(%rsp),%rbx
lea    0xdac(%rip),%r13
lea    0x5(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xd85(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x4,%r9d
call   1070 <sendto@plt>
add    $0x1,%ebp
cmp    $0xb,%ebp
jne    1280 <main+0xd0>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.sockaddr*, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = 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 i32
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.sockaddr*
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca [3 x i8]
store i32 0, i32* %1
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
store i32 1, i32* %3
%14 = load i32, i32* %2
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_BROADCAST
%17 = call i32 @setsockopt(i32 %14, i32 %15, i32 %16, i32* %3, i32 4)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 16)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @SOCK_DGRAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = 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** %5)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %61
31: ; preds = %22
%32 = load %struct.addrinfo*, %struct.addrinfo** %5
%33 = icmp ne %struct.addrinfo* %32, null
br i1 %33, label %34, label %60
34: ; preds = %31
%35 = load %struct.addrinfo*, %struct.addrinfo** %5
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 0
%37 = load %struct.sockaddr*, %struct.sockaddr** %36
store %struct.sockaddr* %37, %struct.sockaddr** %7
store i32 0, i32* %9
store i32 0, i32* %9
br label %38
38: ; preds = %56, %34
%39 = load i32, i32* %9
%40 = icmp sle i32 %39, 10
br i1 %40, label %41, label %59
41: ; preds = %38
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%45 = load i32, i32* %9
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i32, i32* %2
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = load %struct.sockaddr*, %struct.sockaddr** %7
%55 = call i32 @sendto(i32 %50, i8* %51, i32 %53, i32 0, %struct.sockaddr* %54, i32 4)
br label %56
56: ; preds = %41
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %38
59: ; preds = %38
br label %60
60: ; preds = %59, %31
br label %61
61: ; preds = %60, %22
%62 = load i32, i32* %2
%63 = call i32 @close(i32 %62)
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
@SOL_SOCKET = global i32 0
@SO_BROADCAST = 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 %struct.addrinfo*
%3 = alloca %struct.addrinfo
%4 = alloca [100 x i8]
%5 = alloca [3 x i8]
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_BROADCAST
%12 = call i32 @setsockopt(i32 %8, i32 %10, i32 %11, i32* %1, i32 4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = bitcast %struct.addrinfo** %2 to i8*
%18 = bitcast %struct.addrinfo* %3 to i8*
%19 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 16)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @SOCK_DGRAM
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = 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** %2)
%25 = icmp eq i32 %24, 0
%26 = load %struct.addrinfo*, %struct.addrinfo** %2
%27 = icmp ne %struct.addrinfo* %26, null
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %44
29: ; preds = %16
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%31 = load %struct.sockaddr*, %struct.sockaddr** %30
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
br label %34
34: ; preds = %29, %34
%35 = phi i32 [ 0, %29 ], [ %41, %34 ]
%36 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @sprintf(i8* %33, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%38 = call i32 @strcat(i8* %32, i8* %33)
%39 = call i32 @strlen(i8* %32)
%40 = call i32 @sendto(i32 %8, i8* %32, i32 %39, i32 0, %struct.sockaddr* %31, i32 4)
%41 = add nuw nsw i32 %35, 1
%42 = icmp eq i32 %41, 11
br i1 %42, label %43, label %34
43: ; preds = %34
br label %44
44: ; preds = %43, %16
%45 = call i32 @close(i32 %8)
ret i32 0
}