#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, scalar_t__);
int main(void) {
  printf("Hello\n");
  printf("World!\n");
  printf("Goodbye\n");
  printf("World!\n");
  fclose(stdout);
  static char buff[2048];
  ssize_t n;
  while ((n = read(STDIN_FILENO, buff, sizeof(buff))) > 0) {
    write(STDERR_FILENO, buff, n);
  }
  if (n < 0) {
    perror("read(2) error");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0x2ec3(%rip),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jle    11e3 <main+0x93>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0x2e97(%rip),%rsi
call   1030 <write@plt>
jmp    119d <main+0x4d>
cmpq   $0x0,-0x10(%rbp)
jge    1206 <main+0xb6>
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <main+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <fclose@plt>
mov    0x2e37(%rip),%r14
mov    (%r14),%edi
lea    0x2ecd(%rip),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11e3 <main+0x93>
mov    0x2e27(%rip),%r15
lea    0x2eb0(%rip),%rbx
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11c0 <main+0x70>
xor    %ecx,%ecx
test   %rax,%rax
js     11f2 <main+0xa2>
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe07(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%ecx
jmp    11ea <main+0x9a>

LLVM IR (-O0):
@.str = [7 x i8] c"Hello\0A\00"
@.str.1 = [8 x i8] c"World!\0A\00"
@.str.2 = [9 x i8] c"Goodbye\0A\00"
@stdout = global i32 0
@main.buff = internal global [2048 x i8] zeroinitializer
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.3 = [14 x i8] c"read(2) error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fclose(i32 %7)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* @STDIN_FILENO
%11 = call i64 @read(i32 %10, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @main.buff, i64 0, i64 0), i32 2048)
store i64 %11, i64* %2
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @STDERR_FILENO
%15 = load i64, i64* %2
%16 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @main.buff, i64 0, i64 0), i64 %15)
br label %9
17: ; preds = %9
%18 = load i64, i64* %2
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %23
22: ; preds = %17
store i32 0, i32* %1
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@stdout = global i32 0
@main.buff = internal global [2048 x i8] zeroinitializer
@STDIN_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.3 = [14 x i8] c"read(2) error\00"
@str = [6 x i8] c"Hello\00"
@str.5 = [8 x i8] c"Goodbye\00"
@str.6 = [7 x i8] c"World!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = tail call i32 @fclose(i32 %5)
%7 = load i32, i32* @STDIN_FILENO
%8 = tail call i64 @read(i32 %7, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @main.buff, i64 0, i64 0), i32 2048)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %0, %10
%11 = phi i64 [ %15, %10 ], [ %8, %0 ]
%12 = load i32, i32* @STDERR_FILENO
%13 = tail call i32 @write(i32 %12, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @main.buff, i64 0, i64 0), i64 %11)
%14 = load i32, i32* @STDIN_FILENO
%15 = tail call i64 @read(i32 %14, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @main.buff, i64 0, i64 0), i32 2048)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %10, label %17
17: ; preds = %10, %0
%18 = phi i64 [ %8, %0 ], [ %15, %10 ]
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %17, %20
%23 = phi i32 [ 1, %20 ], [ 0, %17 ]
ret i32 %23
}