#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 */
struct stream {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sclose(struct stream *);
int sgetc(struct stream *);
struct stream *sopen_fd(char *, int);
int /*<<< orphan*/ sputc(struct stream *, int);
int main(void) {
  struct stream *i = sopen_fd("stdin", 0);
  struct stream *o = sopen_fd("stdout", 1);
  int c;
  while ((c = sgetc(i)) >= 0)
    sputc(o, c);
  sclose(i);
  sclose(o);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
call   1050 <sopen_fd@plt>
mov    %rax,-0x10(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x1,%esi
call   1050 <sopen_fd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sgetc@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     119c <main+0x5c>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <sputc@plt>
jmp    1176 <main+0x36>
mov    -0x10(%rbp),%rdi
call   1040 <sclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <sclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
xor    %esi,%esi
call   1050 <sopen_fd@plt>
mov    %rax,%r14
lea    0xeaa(%rip),%rdi
mov    $0x1,%esi
call   1050 <sopen_fd@plt>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <sgetc@plt>
test   %eax,%eax
js     1188 <main+0x48>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <sputc@plt>
jmp    1170 <main+0x30>
mov    %r14,%rdi
call   1040 <sclose@plt>
mov    %rbx,%rdi
call   1040 <sclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stream = type { i32 }
@.str = [6 x i8] c"stdin\00"
@.str.1 = [7 x i8] c"stdout\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stream*
%3 = alloca %struct.stream*
%4 = alloca i32
store i32 0, i32* %1
%5 = call %struct.stream* @sopen_fd(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
store %struct.stream* %5, %struct.stream** %2
%6 = call %struct.stream* @sopen_fd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
store %struct.stream* %6, %struct.stream** %3
br label %7
7: ; preds = %11, %0
%8 = load %struct.stream*, %struct.stream** %2
%9 = call i32 @sgetc(%struct.stream* %8)
store i32 %9, i32* %4
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load %struct.stream*, %struct.stream** %3
%13 = load i32, i32* %4
%14 = call i32 @sputc(%struct.stream* %12, i32 %13)
br label %7
15: ; preds = %7
%16 = load %struct.stream*, %struct.stream** %2
%17 = call i32 @sclose(%struct.stream* %16)
%18 = load %struct.stream*, %struct.stream** %3
%19 = call i32 @sclose(%struct.stream* %18)
ret i32 0
}

LLVM IR (-O2):
%struct.stream = type { i32 }
@.str = [6 x i8] c"stdin\00"
@.str.1 = [7 x i8] c"stdout\00"
define i32 @main() {
%1 = tail call %struct.stream* @sopen_fd(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = tail call %struct.stream* @sopen_fd(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = tail call i32 @sgetc(%struct.stream* %1)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %10
5: ; preds = %0, %5
%6 = phi i32 [ %8, %5 ], [ %3, %0 ]
%7 = tail call i32 @sputc(%struct.stream* %2, i32 %6)
%8 = tail call i32 @sgetc(%struct.stream* %1)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %5, label %10
10: ; preds = %5, %0
%11 = tail call i32 @sclose(%struct.stream* %1)
%12 = tail call i32 @sclose(%struct.stream* %2)
ret i32 0
}