#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*/ out_msg;
typedef int /*<<< orphan*/ err_msg;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  char out_msg[] = "Here is a out msg!\n";
  char err_msg[] = "Here is a err msg!\n";
  char buf[256 * 4];
  int ret = 0;
  write(1, out_msg, sizeof(out_msg));
  write(2, err_msg, sizeof(err_msg));
  memset(buf, 0, sizeof(buf));
  ret = read(0, buf, sizeof(buf));
  if (ret < 0) {
    write(2, "Read err\n", 10);
  }
  write(1, buf, ret);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea2(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea3(%rip),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x444(%rbp)
lea    -0x20(%rbp),%rsi
mov    $0x1,%edi
mov    $0x14,%edx
call   1030 <write@plt>
lea    -0x40(%rbp),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
call   1030 <write@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x440(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x444(%rbp)
cmpl   $0x0,-0x444(%rbp)
jge    120f <main+0xcf>
mov    $0x2,%edi
lea    0xe2f(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
lea    -0x440(%rbp),%rsi
mov    -0x444(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x440,%rsp
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0xa2167,0x30(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0xa2167,0x10(%rsp)
lea    0x20(%rsp),%rsi
mov    $0x1,%edi
mov    $0x14,%edx
call   1030 <write@plt>
mov    %rsp,%rsi
mov    $0x2,%edi
mov    $0x14,%edx
call   1030 <write@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11d4 <main+0x94>
lea    0xe6f(%rip),%rsi
mov    $0x2,%edi
mov    $0xa,%edx
call   1030 <write@plt>
lea    0x40(%rsp),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.out_msg = [20 x i8] c"Here is a out msg!\0A\00"
@__const.main.err_msg = [20 x i8] c"Here is a err msg!\0A\00"
@.str = [10 x i8] c"Read err\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [20 x i8]* %2 to i8*
%7 = bitcast [20 x i8]* %3 to i8*
store i32 0, i32* %5
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 @write(i32 1, i8* %8, i32 20)
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%11 = call i32 @write(i32 2, i8* %10, i32 20)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 1024)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @read(i32 0, i8* %14, i32 1024)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @write(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 10)
br label %20
20: ; preds = %18, %0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i32 @write(i32 1, i8* %21, i32 %22)
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.out_msg = [20 x i8] c"Here is a out msg!\0A\00"
@__const.main.err_msg = [20 x i8] c"Here is a err msg!\0A\00"
@.str = [10 x i8] c"Read err\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @write(i32 1, i8* %4, i32 20)
%8 = call i32 @write(i32 2, i8* %5, i32 20)
%9 = call i32 @memset(i8* %6, i32 0, i32 1024)
%10 = call i32 @read(i32 0, i8* %6, i32 1024)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @write(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 10)
br label %14
14: ; preds = %12, %0
%15 = call i32 @write(i32 1, i8* %6, i32 %10)
%16 = call i32 @exit(i32 0)
unreachable
}