#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int udp_send() {
  register int i;
  int n;
  char buffer;
  int sock;
  struct sockaddr_in addr;
  if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "socket error\n");
    exit(1);
  }
  memset(&addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    fprintf(stderr, "connect failed\n");
    exit(1);
  }
  for (i = 0; i < 1024 * 1024 * 16; i++)
    write(sock, &buffer, 1);
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11cc <udp_send+0x4c>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x9,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe12(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    123d <udp_send+0xbd>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1000000,-0x8(%rbp)
jge    1270 <udp_send+0xf0>
mov    -0x14(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1244 <udp_send+0xc4>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     122d <udp_send+0xad>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x9,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe2d(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     123f <udp_send+0xbf>
mov    $0x1000000,%ebp
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    1210 <udp_send+0x90>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
jmp    124f <udp_send+0xcf>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"socket error\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [16 x i8] c"connect failed\0A\00"
define i32 @udp_send() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 9)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %5
%25 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%26 = call i32 @connect(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %15
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %15
store i32 0, i32* %2
br label %33
33: ; preds = %39, %32
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 16777216
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* %5
%38 = call i32 @write(i32 %37, i8* %4, i32 1)
br label %39
39: ; preds = %36
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %33
42: ; preds = %33
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"socket error\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [16 x i8] c"connect failed\0A\00"
define i32 @udp_send() {
%1 = alloca i8
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 9)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%21 = call i32 @connect(i32 %6, %struct.sockaddr* %20, i32 12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %12, %27
%28 = phi i32 [ %30, %27 ], [ 0, %12 ]
%29 = call i32 @write(i32 %6, i8* %1, i32 1)
%30 = add nuw nsw i32 %28, 1
%31 = icmp eq i32 %30, 16777216
br i1 %31, label %32, label %27
32: ; preds = %27
ret i32 undef
}