#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 */

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ test_fmt(char *, int);
int /*<<< orphan*/ test_fopen(char const *);
int /*<<< orphan*/ test_fp();
int /*<<< orphan*/ test_malloc();
int /*<<< orphan*/ test_time();
int write(int, char const *, int /*<<< orphan*/);
int NaClMain(const char *fn) {
  char const *hello = "Hello world\n";
  char const *bye = "Goodbye cruel world";
  int r;
  r = write(1, hello, strlen(hello));
  printf("write returned %d.\n", r);
  test_fmt("<%04d>", r);
  test_fmt("<%-d>", r);
  test_fmt("<%-04d>", r);
  r = -r;
  test_fmt("<%d>", r);
  test_fmt("<%04d>", r);
  test_fmt("<%-d>", r);
  test_fmt("<%-04d>", r);
  printf("The message was \"%s\".\n", hello);
  printf("Bye message: \"%25s\".\n", bye);
  printf("Bye message: \"%-25s\".\n", bye);
  test_fp();
  test_malloc();
  test_time();
  test_fopen(fn);
  fflush(0);
  fprintf(stderr, "# Hello is at address 0x%08lx\n", (long)hello);
  fprintf(stderr, "# Hello is at address %p\n", hello);
  {
    short s = -1;
    unsigned short us = (unsigned short)-1;
    printf("s = %hd\n", s);
    printf("us = %hu\n", us);
  }
  printf("Goodbye cruel world.  Really.\n");
  fprintf(stderr, "My pid is %d\n", getpid());
  fflush(0);
  return 0;
}


x86 assembly (clang, -O0):
<NaClMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe24(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x1c(%rbp),%esi
lea    0xe1c(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x1c(%rbp),%esi
lea    0xe13(%rip),%rdi
call   10c0 <test_fmt@plt>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe04(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x1c(%rbp),%esi
lea    0xde0(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x1c(%rbp),%esi
lea    0xdd8(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x1c(%rbp),%esi
lea    0xdcf(%rip),%rdi
call   10c0 <test_fmt@plt>
mov    -0x10(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   10d0 <test_fp@plt>
mov    $0x0,%al
call   1030 <test_malloc@plt>
mov    $0x0,%al
call   10a0 <test_time@plt>
mov    -0x8(%rbp),%rdi
call   1060 <test_fopen@plt>
xor    %edi,%edi
call   10b0 <fflush@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movw   $0xffff,-0x1e(%rbp)
movw   $0xffff,-0x20(%rbp)
movswl -0x1e(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movzwl -0x20(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10b0 <fflush@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NaClMain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe2b(%rip),%r15
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,%ebp
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xe30(%rip),%r12
mov    %r12,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
lea    0xe26(%rip),%r13
mov    %r13,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
lea    0xe1b(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
neg    %ebp
lea    0xe10(%rip),%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
mov    %r13,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10d0 <test_fmt@plt>
lea    0xde9(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdef(%rip),%rdi
lea    0xd8f(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xded(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   10e0 <test_fp@plt>
xor    %eax,%eax
call   1030 <test_malloc@plt>
xor    %eax,%eax
call   10b0 <test_time@plt>
mov    %r14,%rdi
call   1070 <test_fopen@plt>
xor    %edi,%edi
call   10c0 <fflush@plt>
mov    0x2d1c(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc6(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd2(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xddb(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdd1(%rip),%rdi
mov    $0xffff,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdd6(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdb3(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Hello world\0A\00"
@.str.1 = [20 x i8] c"Goodbye cruel world\00"
@.str.2 = [20 x i8] c"write returned %d.\0A\00"
@.str.3 = [7 x i8] c"<%04d>\00"
@.str.4 = [6 x i8] c"<%-d>\00"
@.str.5 = [8 x i8] c"<%-04d>\00"
@.str.6 = [5 x i8] c"<%d>\00"
@.str.7 = [23 x i8] c"The message was \22%s\22.\0A\00"
@.str.8 = [22 x i8] c"Bye message: \22%25s\22.\0A\00"
@.str.9 = [23 x i8] c"Bye message: \22%-25s\22.\0A\00"
@stderr = global i32 0
@.str.10 = [31 x i8] c"# Hello is at address 0x%08lx\0A\00"
@.str.11 = [26 x i8] c"# Hello is at address %p\0A\00"
@.str.12 = [9 x i8] c"s = %hd\0A\00"
@.str.13 = [10 x i8] c"us = %hu\0A\00"
@.str.14 = [31 x i8] c"Goodbye cruel world. Really.\0A\00"
@.str.15 = [14 x i8] c"My pid is %d\0A\00"
define i32 @NaClMain(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16
%7 = alloca i16
store i8* %0, i8** %2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %4
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @write(i32 1, i8* %8, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @test_fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = call i32 @test_fmt(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = call i32 @test_fmt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = sub nsw i32 0, %20
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = call i32 @test_fmt(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %5
%25 = call i32 @test_fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @test_fmt(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %5
%29 = call i32 @test_fmt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %34)
%36 = call i32 (...) @test_fp()
%37 = call i32 (...) @test_malloc()
%38 = call i32 (...) @test_time()
%39 = load i8*, i8** %2
%40 = call i32 @test_fopen(i8* %39)
%41 = call i32 @fflush(i32 0)
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %3
%44 = ptrtoint i8* %43 to i64
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i64 %44)
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %47)
store i16 -1, i16* %6
store i16 -1, i16* %7
%49 = load i16, i16* %6
%50 = sext i16 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %50)
%52 = load i16, i16* %7
%53 = zext i16 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
%56 = load i32, i32* @stderr
%57 = call i32 (...) @getpid()
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0), i32 %57)
%59 = call i32 @fflush(i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello world\0A\00"
@.str.1 = [20 x i8] c"Goodbye cruel world\00"
@.str.2 = [20 x i8] c"write returned %d.\0A\00"
@.str.3 = [7 x i8] c"<%04d>\00"
@.str.4 = [6 x i8] c"<%-d>\00"
@.str.5 = [8 x i8] c"<%-04d>\00"
@.str.6 = [5 x i8] c"<%d>\00"
@.str.7 = [23 x i8] c"The message was \22%s\22.\0A\00"
@.str.8 = [22 x i8] c"Bye message: \22%25s\22.\0A\00"
@.str.9 = [23 x i8] c"Bye message: \22%-25s\22.\0A\00"
@stderr = global i32 0
@.str.10 = [31 x i8] c"# Hello is at address 0x%08lx\0A\00"
@.str.11 = [26 x i8] c"# Hello is at address %p\0A\00"
@.str.12 = [9 x i8] c"s = %hd\0A\00"
@.str.13 = [10 x i8] c"us = %hu\0A\00"
@.str.15 = [14 x i8] c"My pid is %d\0A\00"
@str = [30 x i8] c"Goodbye cruel world. Really.\00"
define i32 @NaClMain(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = tail call i32 @test_fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%6 = tail call i32 @test_fmt(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %3)
%7 = tail call i32 @test_fmt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %3)
%8 = sub nsw i32 0, %3
%9 = tail call i32 @test_fmt(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %8)
%10 = tail call i32 @test_fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%11 = tail call i32 @test_fmt(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%12 = tail call i32 @test_fmt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %8)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (...) @test_fp()
%17 = tail call i32 (...) @test_malloc()
%18 = tail call i32 (...) @test_time()
%19 = tail call i32 @test_fopen(i8* %0)
%20 = tail call i32 @fflush(i32 0)
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i64 ptrtoint ([13 x i8]* @.str to i64))
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 -1)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 65535)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = tail call i32 (...) @getpid()
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0), i32 %29)
%31 = tail call i32 @fflush(i32 0)
ret i32 0
}