#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  struct sockaddr_in addr = {0};
  int port, num, s, interval = 0;
  if (argc < 3) {
    fprintf(stderr, "usage: udp_send port num_packets [interval]\n");
    exit(EXIT_FAILURE);
  }
  port = atoi(argv[1]);
  num = atoi(argv[2]);
  if (argc > 3) {
    interval = atoi(argv[3]);
  }
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
    fprintf(stderr, "failed to create socket\n");
    exit(EXIT_FAILURE);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  inet_aton("127.0.0.1", &addr.sin_addr);
  while (num--) {
    char *message = "if not now, when?";
    int ret;
    ret = sendto(s, message, strlen(message), 0, (struct sockaddr *)&addr,
                 sizeof(addr));
    if (ret < 0) {
      fprintf(stderr, "failed to send message\n");
      exit(EXIT_FAILURE);
    }
    sleep(interval);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fa <main+0x5a>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1234 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1283 <main+0xe3>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xda1(%rip),%rdi
call   1080 <inet_aton@plt>
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
cmp    $0x0,%eax
je     1337 <main+0x197>
lea    0xd8b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    132a <main+0x18a>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%edi
call   10b0 <sleep@plt>
jmp    12aa <main+0x10a>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jle    12a5 <main+0x115>
mov    %rsi,%rbp
mov    %edi,%r12d
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
xor    %r14d,%r14d
cmp    $0x3,%r12d
je     11de <main+0x4e>
mov    0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x2e03(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     12b7 <main+0x127>
mov    %eax,%r12d
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe22(%rip),%rdi
mov    %rsp,%rsi
call   1070 <inet_aton@plt>
test   %ebx,%ebx
je     1273 <main+0xe3>
lea    0xe19(%rip),%rbp
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x10,%r9d
call   1050 <sendto@plt>
test   %eax,%eax
js     1282 <main+0xf2>
add    $0xffffffff,%ebx
mov    %r14d,%edi
call   10a0 <sleep@plt>
test   %ebx,%ebx
jne    1240 <main+0xb0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
jmp    1292 <main+0x102>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
jmp    1292 <main+0x102>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"usage: udp_send port num_packets [interval]\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [25 x i8] c"failed to create socket\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [18 x i8] c"if not now, when?\00"
@.str.4 = [24 x i8] c"failed to send message\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 i32
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast %struct.sockaddr_in* %6 to i8*
store i32 0, i32* %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 3
br i1 %31, label %32, label %37
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %10
br label %37
37: ; preds = %32, %21
%38 = load i32, i32* @AF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = load i32, i32* @IPPROTO_UDP
%41 = call i32 @socket(i32 %38, i32 %39, i32 %40)
store i32 %41, i32* %9
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %49, i32* %50
%51 = load i32, i32* %7
%52 = call i32 @htons(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %52, i32* %53
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%55 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %54)
br label %56
56: ; preds = %74, %48
%57 = load i32, i32* %8
%58 = add nsw i32 %57, -1
store i32 %58, i32* %8
%59 = icmp ne i32 %57, 0
br i1 %59, label %60, label %77
60: ; preds = %56
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %11
%61 = load i32, i32* %9
%62 = load i8*, i8** %11
%63 = load i8*, i8** %11
%64 = call i32 @strlen(i8* %63)
%65 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%66 = call i32 @sendto(i32 %61, i8* %62, i32 %64, i32 0, %struct.sockaddr* %65, i32 16)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %60
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %60
%75 = load i32, i32* %10
%76 = call i32 @sleep(i32 %75)
br label %56
77: ; preds = %56
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"usage: udp_send port num_packets [interval]\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [25 x i8] c"failed to create socket\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [18 x i8] c"if not now, when?\00"
@.str.4 = [24 x i8] c"failed to send message\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp eq i32 %0, 3
br i1 %18, label %23, label %19
19: ; preds = %11
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
br label %23
23: ; preds = %19, %11
%24 = phi i32 [ %22, %19 ], [ 0, %11 ]
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = load i32, i32* @IPPROTO_UDP
%28 = tail call i32 @socket(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %23
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %36, i32* %37
%38 = tail call i32 @htons(i32 %14)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%41 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %40)
%42 = icmp eq i32 %17, 0
br i1 %42, label %59, label %43
43: ; preds = %35
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %45
45: ; preds = %43, %56
%46 = phi i32 [ %17, %43 ], [ %47, %56 ]
%47 = add nsw i32 %46, -1
%48 = call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @sendto(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 0, %struct.sockaddr* %44, i32 16)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %45
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45
%57 = call i32 @sleep(i32 %24)
%58 = icmp eq i32 %47, 0
br i1 %58, label %59, label %45
59: ; preds = %56, %35
ret i32 0
}