#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 fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  static char buff[1024];
  int len;
  printf("Hello world!\n");
  while ((len = fread(buff, 1, 1024, stdin)) > 0) {
    fwrite(buff, 1, len, stdout);
  }
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%ecx
lea    0x2ee5(%rip),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11a8 <main+0x68>
mov    -0x8(%rbp),%edx
mov    0x2e48(%rip),%rax
mov    (%rax),%ecx
lea    0x2eb7(%rip),%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    115b <main+0x1b>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e90(%rip),%r14
mov    (%r14),%ecx
lea    0x2eee(%rip),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
test   %eax,%eax
jle    11bb <main+0x7b>
mov    0x2e5c(%rip),%r15
lea    0x2ecd(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1060 <fwrite@plt>
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
test   %eax,%eax
jg     1190 <main+0x50>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.buff = internal global [1024 x i8] zeroinitializer
@.str = [14 x i8] c"Hello world!\0A\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %8, %0
%5 = load i32, i32* @stdin
%6 = call i32 @fread(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.buff, i64 0, i64 0), i32 1, i32 1024, i32 %5)
store i32 %6, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* %2
%10 = load i32, i32* @stdout
%11 = call i32 @fwrite(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.buff, i64 0, i64 0), i32 1, i32 %9, i32 %10)
br label %4
12: ; preds = %4
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
ret i32 0
}

LLVM IR (-O2):
@main.buff = internal global [1024 x i8] zeroinitializer
@stdin = global i32 0
@stdout = global i32 0
@str = [13 x i8] c"Hello world!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = load i32, i32* @stdin
%3 = tail call i32 @fread(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.buff, i64 0, i64 0), i32 1, i32 1024, i32 %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0, %5
%6 = phi i32 [ %10, %5 ], [ %3, %0 ]
%7 = load i32, i32* @stdout
%8 = tail call i32 @fwrite(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.buff, i64 0, i64 0), i32 1, i32 %6, i32 %7)
%9 = load i32, i32* @stdin
%10 = tail call i32 @fread(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.buff, i64 0, i64 0), i32 1, i32 1024, i32 %9)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %5, %0
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
ret i32 0
}