#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*/ you_wrote;
typedef int /*<<< orphan*/ stdout_text;
typedef int /*<<< orphan*/ stderr_text;
typedef int /*<<< orphan*/ hello;

/* Variables and functions */
int syscall_read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ syscall_write(int, char *, int);
int main() {
  char text_read[58];
  int read_length;
  char hello[] = "HELLO THERE!  WRITE SOMETHING!\n";
  char you_wrote[] = "YOU WROTE: ";
  char stderr_text[] = "Here's something for stderr..\n";
  char stdout_text[] = "Writing to stdout..\n";
  syscall_write(1, stdout_text, sizeof(stdout_text));
  syscall_write(2, stderr_text, sizeof(stderr_text));
  syscall_write(1, stdout_text, sizeof(stdout_text));
  syscall_write(1, hello, sizeof(hello));
  read_length = syscall_read(0, text_read, 58);
  syscall_write(1, you_wrote, sizeof(you_wrote));
  syscall_write(1, text_read, read_length);
  syscall_write(1, "\n", 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xef0(%rip),%rax
mov    %rax,-0x7c(%rbp)
mov    0xeee(%rip),%eax
mov    %eax,-0x74(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xea1(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0xe96(%rip),%eax
mov    %eax,-0x88(%rbp)
mov    0xe8d(%rip),%ax
mov    %ax,-0x84(%rbp)
mov    0xe82(%rip),%al
mov    %al,-0x82(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xe71(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    0xe6c(%rip),%eax
mov    %eax,-0xb0(%rbp)
mov    0xe64(%rip),%al
mov    %al,-0xac(%rbp)
lea    -0xc0(%rbp),%rsi
mov    $0x1,%edi
mov    $0x15,%edx
call   1030 <syscall_write@plt>
lea    -0xa0(%rbp),%rsi
mov    $0x2,%edi
mov    $0x1f,%edx
call   1030 <syscall_write@plt>
lea    -0xc0(%rbp),%rsi
mov    $0x1,%edi
mov    $0x15,%edx
call   1030 <syscall_write@plt>
lea    -0x70(%rbp),%rsi
mov    $0x1,%edi
mov    $0x20,%edx
call   1030 <syscall_write@plt>
lea    -0x40(%rbp),%rsi
xor    %edi,%edi
mov    $0x3a,%edx
call   1040 <syscall_read@plt>
mov    %eax,-0x44(%rbp)
lea    -0x7c(%rbp),%rsi
mov    $0x1,%edi
mov    $0xc,%edx
call   1030 <syscall_write@plt>
lea    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    $0x1,%edi
call   1030 <syscall_write@plt>
mov    $0x1,%edx
lea    0xdd3(%rip),%rsi
mov    %edx,%edi
call   1030 <syscall_write@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xb8,%rsp
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movabs $0x544f525720554f59,%rax
52 4f 54
mov    %rax,(%rsp)
movl   $0x203a45,0x8(%rsp)
movups 0xed1(%rip),%xmm0
movups %xmm0,0x3f(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa2e2e74756f64,%rax
mov    %rax,0x1d(%rsp)
lea    0x10(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x15,%edx
call   1030 <syscall_write@plt>
lea    0x30(%rsp),%rsi
mov    $0x2,%edi
mov    $0x1f,%edx
call   1030 <syscall_write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x15,%edx
call   1030 <syscall_write@plt>
lea    0x50(%rsp),%rsi
mov    $0x1,%edi
mov    $0x20,%edx
call   1030 <syscall_write@plt>
lea    0x70(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3a,%edx
call   1040 <syscall_read@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0xc,%edx
call   1030 <syscall_write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <syscall_write@plt>
lea    0xe48(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <syscall_write@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.hello = [32 x i8] c"HELLO THERE! WRITE SOMETHING!\0A\00"
@__const.main.you_wrote = [12 x i8] c"YOU WROTE: \00"
@__const.main.stderr_text = [31 x i8] c"Here's something for stderr..\0A\00"
@__const.main.stdout_text = [21 x i8] c"Writing to stdout..\0A\00"
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [58 x i8]
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca [12 x i8]
%6 = alloca [31 x i8]
%7 = alloca [21 x i8]
store i32 0, i32* %1
%8 = bitcast [32 x i8]* %4 to i8*
%9 = bitcast [12 x i8]* %5 to i8*
%10 = bitcast [31 x i8]* %6 to i8*
%11 = bitcast [21 x i8]* %7 to i8*
%12 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%13 = call i32 @syscall_write(i32 1, i8* %12, i32 21)
%14 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%15 = call i32 @syscall_write(i32 2, i8* %14, i32 31)
%16 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%17 = call i32 @syscall_write(i32 1, i8* %16, i32 21)
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%19 = call i32 @syscall_write(i32 1, i8* %18, i32 32)
%20 = getelementptr inbounds [58 x i8], [58 x i8]* %2, i64 0, i64 0
%21 = call i32 @syscall_read(i32 0, i8* %20, i32 58)
store i32 %21, i32* %3
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%23 = call i32 @syscall_write(i32 1, i8* %22, i32 12)
%24 = getelementptr inbounds [58 x i8], [58 x i8]* %2, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @syscall_write(i32 1, i8* %24, i32 %25)
%27 = call i32 @syscall_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
ret i32 0
}

LLVM IR (-O2):
@__const.main.hello = [32 x i8] c"HELLO THERE! WRITE SOMETHING!\0A\00"
@__const.main.you_wrote = [12 x i8] c"YOU WROTE: \00"
@__const.main.stderr_text = [31 x i8] c"Here's something for stderr..\0A\00"
@__const.main.stdout_text = [21 x i8] c"Writing to stdout..\0A\00"
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [58 x i8]
%2 = alloca [32 x i8]
%3 = alloca [12 x i8]
%4 = alloca [31 x i8]
%5 = alloca [21 x i8]
%6 = getelementptr inbounds [58 x i8], [58 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [31 x i8], [31 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%11 = call i32 @syscall_write(i32 1, i8* %10, i32 21)
%12 = call i32 @syscall_write(i32 2, i8* %9, i32 31)
%13 = call i32 @syscall_write(i32 1, i8* %10, i32 21)
%14 = call i32 @syscall_write(i32 1, i8* %7, i32 32)
%15 = call i32 @syscall_read(i32 0, i8* %6, i32 58)
%16 = call i32 @syscall_write(i32 1, i8* %8, i32 12)
%17 = call i32 @syscall_write(i32 1, i8* %6, i32 %15)
%18 = call i32 @syscall_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
ret i32 0
}