#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_buf;

/* Variables and functions */
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ s_close(int);
int s_open();
int strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main(void) {
  int fd, c;
  char in_buf[255], out_buf[255], *in_ptr, *out_ptr;
  fd = s_open();
  printf("s_open returned,<%d>\n", fd);
  out_ptr = out_buf;
  bzero(out_buf, sizeof(out_buf));
  *out_ptr++ = 'h';
  *out_ptr++ = 'i';
  *out_ptr++ = ' ';
  *out_ptr++ = 'y';
  *out_ptr++ = 'o';
  *out_ptr++ = 'u';
  *out_ptr++ = '\n';
  *out_ptr = 27;
  printf("out_buf size  = %d\n", sizeof(out_buf));
  printf("string length = %d\n", strlen(out_buf));
  write(fd, out_buf, strlen(out_buf));
  while (c != 'q') {
    if (read(fd, &c, 1) > 0)
      write(STDOUT_FILENO, &c, 1);
    if (read(STDIN_FILENO, &c, 1) > 0)
      write(fd, &c, 1);
  }
  s_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <s_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6a(%rip),%rdi
call   1070 <printf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0xff,%esi
call   1090 <bzero@plt>
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x68,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x69,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x20,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x79,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x6f,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x75,(%rax)
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0xa,(%rax)
mov    -0x220(%rbp),%rax
movb   $0x1b,(%rax)
lea    0xda3(%rip),%rdi
mov    $0xff,%esi
call   1070 <printf@plt>
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xd98(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmpl   $0x71,-0xc(%rbp)
je     1347 <main+0x1d7>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jle    130e <main+0x19e>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jle    1342 <main+0x1d2>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
jmp    12d0 <main+0x160>
mov    -0x8(%rbp),%edi
call   1030 <s_close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
xor    %eax,%eax
call   1060 <s_open@plt>
mov    %eax,%ebp
lea    0xe73(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1090 <bzero@plt>
movabs $0x1b0a756f79206968,%rax
75 0a 1b
mov    %rax,0x10(%rsp)
lea    0xe5a(%rip),%rdi
mov    $0xff,%esi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
lea    0xc(%rsp),%rbx
mov    0x2df2(%rip),%r14
mov    0x2dd3(%rip),%r15
jmp    1217 <main+0xa7>
nopw   0x0(%rax,%rax,1)
cmpl   $0x71,0xc(%rsp)
je     1265 <main+0xf5>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    123d <main+0xcd>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    1210 <main+0xa0>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
jmp    1210 <main+0xa0>
mov    %ebp,%edi
call   1030 <s_close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"s_open returned,<%d>\0A\00"
@.str.1 = [20 x i8] c"out_buf size = %d\0A\00"
@.str.2 = [20 x i8] c"string length = %d\0A\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
%8 = call i32 (...) @s_open()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
store i8* %11, i8** %7
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%13 = call i32 @bzero(i8* %12, i32 255)
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %7
store i8 104, i8* %14
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %7
store i8 105, i8* %16
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %7
store i8 32, i8* %18
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %7
store i8 121, i8* %20
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
store i8 111, i8* %22
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
store i8 117, i8* %24
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %7
store i8 10, i8* %26
%28 = load i8*, i8** %7
store i8 27, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 255)
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = call i32 (i32, ...) @write(i32 %33, i8* %34, i32 %36)
br label %38
38: ; preds = %55, %0
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 113
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = load i32, i32* %2
%43 = call i64 @read(i32 %42, i32* %3, i32 1)
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @STDOUT_FILENO
%47 = call i32 (i32, ...) @write(i32 %46, i32* %3, i32 1)
br label %48
48: ; preds = %45, %41
%49 = load i32, i32* @STDIN_FILENO
%50 = call i64 @read(i32 %49, i32* %3, i32 1)
%51 = icmp sgt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %2
%54 = call i32 (i32, ...) @write(i32 %53, i32* %3, i32 1)
br label %55
55: ; preds = %52, %48
br label %38
56: ; preds = %38
%57 = load i32, i32* %2
%58 = call i32 @s_close(i32 %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"s_open returned,<%d>\0A\00"
@.str.1 = [20 x i8] c"out_buf size = %d\0A\00"
@.str.2 = [20 x i8] c"string length = %d\0A\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @s_open()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @bzero(i8* %4, i32 255)
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 1
store i8 104, i8* %4
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 2
store i8 105, i8* %8
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 3
store i8 32, i8* %9
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 4
store i8 121, i8* %10
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 5
store i8 111, i8* %11
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 6
store i8 117, i8* %12
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 7
store i8 10, i8* %13
store i8 27, i8* %14
%15 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 255)
%16 = call i32 @strlen(i8* %4)
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 @strlen(i8* %4)
%19 = call i32 (i32, ...) @write(i32 %5, i8* %4, i32 %18)
br label %20
20: ; preds = %0, %32
%21 = call i64 @read(i32 %5, i32* %1, i32 1)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i32 (i32, ...) @write(i32 %24, i32* %1, i32 1)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* @STDIN_FILENO
%28 = call i64 @read(i32 %27, i32* %1, i32 1)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i32, ...) @write(i32 %5, i32* %1, i32 1)
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* %1
%34 = icmp eq i32 %33, 113
br i1 %34, label %35, label %20
35: ; preds = %32
%36 = call i32 @s_close(i32 %5)
ret i32 0
}