#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  char buf[100];
  int len;
  while (1) {
    printf("in. %s\n", buf);
    len = read(STDIN_FILENO, buf, 10);
    printf("out. %s\n", buf);
    write(STDOUT_FILENO, buf, len);
    printf("end. %s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1030 <write@plt>
lea    -0x70(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
jmp    1142 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsp,%rbx
mov    0x2e90(%rip),%r13
lea    0xeb9(%rip),%r15
mov    0x2e9a(%rip),%r14
lea    0xeb4(%rip),%r12
nopl   (%rax)
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    1160 <main+0x30>

LLVM IR (-O0):
@.str = [8 x i8] c"in. %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.1 = [9 x i8] c"out. %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [9 x i8] c"end. %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %0, %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @STDIN_FILENO
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 10)
store i32 %9, i32* %3
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @STDOUT_FILENO
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @write(i32 %12, i8* %13, i32 %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %4
}

LLVM IR (-O2):
@.str = [8 x i8] c"in. %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.1 = [9 x i8] c"out. %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [9 x i8] c"end. %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %2, i32 10)
%7 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @write(i32 %8, i8* %2, i32 %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %3
}