#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;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ si_other;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
int main(void) {
  struct sockaddr_in si_other;
  int s, i, slen = sizeof(si_other);
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
    die("socket");
  }
  memset((char *)&si_other, 0, sizeof(si_other));
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons(55400);
  if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
  while (1) {
    char message[10] = "128";
    if (sendto(s, message, strlen(message), 0, (struct sockaddr *)&si_other,
               slen) == -1) {
      die("sendto()");
    }
    usleep(16 * 1000);
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ee <main+0x4e>
lea    0xe17(%rip),%rdi
call   1090 <die@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0xd868,%edi
call   1040 <htons@plt>
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1080 <inet_aton@plt>
cmp    $0x0,%rax
jne    1250 <main+0xb0>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1255 <main+0xb5>
mov    0xdd2(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xdcf(%rip),%ax
mov    %ax,-0x1e(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x26(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x26(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12af <main+0x10f>
lea    0xd7b(%rip),%rdi
call   1090 <die@plt>
mov    $0x3e80,%edi
call   10b0 <usleep@plt>
jmp    1255 <main+0xb5>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e37(%rip),%r14
mov    (%r14),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11de <main+0x3e>
lea    0xe27(%rip),%rdi
call   1090 <die@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    $0xd868,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xdf9(%rip),%rdi
mov    %rbx,%rsi
call   1080 <inet_aton@plt>
test   %rax,%rax
je     1278 <main+0xd8>
lea    0x18(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xdf9(%rip),%r15
jmp    123a <main+0x9a>
xchg   %ax,%ax
mov    $0x3e80,%edi
call   10b0 <usleep@plt>
movw   $0x0,0x20(%rsp)
movq   $0x383231,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1230 <main+0x90>
mov    %r15,%rdi
call   1090 <die@plt>
jmp    1230 <main+0x90>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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 = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"inet_aton() failed\0A\00"
@__const.main.message = [10 x i8] c"128\00\00\00\00\00\00\00"
@.str.3 = [9 x i8] c"sendto()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
store i32 0, i32* %1
store i32 12, i32* %5
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @IPPROTO_UDP
%10 = call i32 @socket(i32 %7, i32 %8, i32 %9)
store i32 %10, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = bitcast %struct.sockaddr_in* %2 to i8*
%16 = call i32 @memset(i8* %15, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 55400)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%22 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %14
br label %29
29: ; preds = %28, %41
%30 = bitcast [10 x i8]* %6 to i8*
%31 = load i32, i32* %3
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = load i32, i32* %5
%37 = call i32 @sendto(i32 %31, i8* %32, i32 %34, i32 0, %struct.sockaddr* %35, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %29
%42 = call i32 @usleep(i32 16000)
br label %29
}

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 = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"inet_aton() failed\0A\00"
@__const.main.message = [10 x i8] c"128\00\00\00\00\00\00\00"
@.str.3 = [9 x i8] c"sendto()\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [10 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @IPPROTO_UDP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i32 @memset(i8* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 55400)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%18 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %27
23: ; preds = %11
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20, %33
%28 = call i32 @strlen(i8* %21)
%29 = call i32 @sendto(i32 %7, i8* %21, i32 %28, i32 0, %struct.sockaddr* %22, i32 12)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = call i32 @usleep(i32 16000)
br label %27
}