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

/* Variables and functions */
int accept(int);
int /*<<< orphan*/ printf(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int connection, bytes;
  char msg[] =
      "this is a long message that will require being fragmented into multiple "
      "packets over the NTP protocol. Yay. I sure hope it works.";
  do {
    connection = accept(2);
  } while (connection == -1);
  bytes = write(connection, msg, sizeof(msg));
  if (bytes == -1) {
    printf("Error : Expected to write all bytes, but wrote -1");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x82,%edx
call   1050 <memcpy@plt>
mov    $0x2,%edi
call   1060 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1171 <main+0x31>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x82,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c1 <main+0x81>
lea    0xed2(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <main+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x88,%rsp
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdi
mov    $0x82,%edx
call   1050 <memcpy@plt>
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
call   1060 <accept@plt>
cmp    $0xffffffff,%eax
je     1160 <main+0x20>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x82,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     118f <main+0x4f>
add    $0x88,%rsp
ret
lea    0xeec(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x88,%rsp
ret

LLVM IR (-O0):
@__const.main.msg = [130 x i8] c"this is a long message that will require being fragmented into multiple packets over the NTP protocol. Yay. I sure hope it works.\00"
@.str = [50 x i8] c"Error : Expected to write all bytes, but wrote -1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [130 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [130 x i8]* %8 to i8*
br label %10
10: ; preds = %12, %2
%11 = call i32 @accept(i32 2)
store i32 %11, i32* %6
br label %12
12: ; preds = %10
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %10, label %15
15: ; preds = %12
%16 = load i32, i32* %6
%17 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 130)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %24
23: ; preds = %15
store i32 0, i32* %3
br label %24
24: ; preds = %23, %21
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@__const.main.msg = [130 x i8] c"this is a long message that will require being fragmented into multiple packets over the NTP protocol. Yay. I sure hope it works.\00"
@.str = [50 x i8] c"Error : Expected to write all bytes, but wrote -1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [130 x i8]
%4 = getelementptr inbounds [130 x i8], [130 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = tail call i32 @accept(i32 2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %5, label %8
8: ; preds = %5
%9 = call i32 @write(i32 %6, i8* %4, i32 130)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ 1, %11 ], [ 0, %8 ]
ret i32 %14
}