#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 /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char buf[0x100];
  printf("swag is king\n");
  fflush(stdout);
  fprintf(stderr, "error is king\n");
  fflush(stderr);
  while (1) {
    int a = read(0, buf, 0x100);
    if (a <= 0)
      break;
    write(1, buf, a);
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x110(%rbp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jg     11ca <main+0x7a>
jmp    11e6 <main+0x96>
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    119f <main+0x4f>
mov    $0xffffffff,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e67(%rip),%rbx
mov    (%rbx),%edi
lea    0xe7e(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11d2 <main+0x82>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11b0 <main+0x60>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"swag is king\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"error is king\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 @fflush(i32 %9)
br label %11
11: ; preds = %0, %17
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = call i32 @read(i32 0, i8* %12, i32 256)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %21
17: ; preds = %11
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 @write(i32 1, i8* %18, i32 %19)
br label %11
21: ; preds = %16
ret i32 -1
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"error is king\0A\00"
@str = [13 x i8] c"swag is king\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fflush(i32 %8)
%10 = call i32 @read(i32 0, i8* %2, i32 256)
%11 = icmp slt i32 %10, 1
br i1 %11, label %17, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %15, %12 ], [ %10, %0 ]
%14 = call i32 @write(i32 1, i8* %2, i32 %13)
%15 = call i32 @read(i32 0, i8* %2, i32 256)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %12
17: ; preds = %12, %0
ret i32 -1
}