#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 read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char buf[80];
  int n;
  write(1, "This is written to fd number 1\n", 31);
  write(2, "This is written to fd number 2\n", 31);
  write(1, "Enter a line of text\n", 21);
  n = read(0, buf, 80);
  write(1, "Following is the line i read\n", 29);
  write(1, buf, n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x1,%edi
lea    0xecc(%rip),%rsi
mov    $0x1f,%edx
call   1030 <write@plt>
mov    $0x2,%edi
lea    0xed6(%rip),%rsi
mov    $0x1f,%edx
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xee0(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
lea    -0x50(%rbp),%rsi
xor    %edi,%edi
mov    $0x50,%edx
call   1040 <read@plt>
mov    %eax,-0x54(%rbp)
mov    $0x1,%edi
lea    0xecd(%rip),%rsi
mov    $0x1d,%edx
call   1030 <write@plt>
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0xed3(%rip),%rsi
mov    $0x1,%edi
mov    $0x1f,%edx
call   1030 <write@plt>
lea    0xedd(%rip),%rsi
mov    $0x2,%edi
mov    $0x1f,%edx
call   1030 <write@plt>
lea    0xee7(%rip),%rsi
mov    $0x1,%edi
mov    $0x15,%edx
call   1030 <write@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1040 <read@plt>
mov    %eax,%ebp
lea    0xed3(%rip),%rsi
mov    $0x1,%edi
mov    $0x1d,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"This is written to fd number 1\0A\00"
@.str.1 = [32 x i8] c"This is written to fd number 2\0A\00"
@.str.2 = [22 x i8] c"Enter a line of text\0A\00"
@.str.3 = [30 x i8] c"Following is the line i read\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = call i32 @write(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 31)
%4 = call i32 @write(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 31)
%5 = call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 21)
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%7 = call i32 @read(i32 0, i8* %6, i32 80)
store i32 %7, i32* %2
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 29)
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @write(i32 1, i8* %9, i32 %10)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"This is written to fd number 1\0A\00"
@.str.1 = [32 x i8] c"This is written to fd number 2\0A\00"
@.str.2 = [22 x i8] c"Enter a line of text\0A\00"
@.str.3 = [30 x i8] c"Following is the line i read\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 31)
%4 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 31)
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 21)
%6 = call i32 @read(i32 0, i8* %2, i32 80)
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 29)
%8 = call i32 @write(i32 1, i8* %2, i32 %6)
ret i32 0
}