#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ getdelim(char **, size_t *, char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int do_stream(char *file_name) {
  FILE *input_stream = stdin;
  FILE *output_stream = stdout;
  if (strcmp(file_name, "-")) {
    input_stream = fopen(file_name, "r");
    if (input_stream == NULL) {
      perror(file_name);
      return 0;
    }
  }
  while (1) {
    char *line = NULL;
    size_t linecap = 0;
    ssize_t linelen = getdelim(&line, &linecap, '\n', input_stream);
    if (linelen <= 0) {
      break;
    }
    fputs(line, output_stream);
    free(line);
  }
  if (input_stream != stdin)
    fclose(input_stream);
  return 1;
}


x86 assembly (clang, -O0):
<do_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11eb <do_stream+0x7b>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e6 <do_stream+0x76>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <do_stream+0xf9>
jmp    11eb <do_stream+0x7b>
jmp    11f0 <do_stream+0x80>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1090 <getdelim@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jg     122a <do_stream+0xba>
jmp    1245 <do_stream+0xd5>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11f0 <do_stream+0x80>
mov    -0x18(%rbp),%rax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
je     1262 <do_stream+0xf2>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_stream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    0x2e60(%rip),%r13
mov    0x0(%r13),%rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%r14
lea    0xe63(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c2 <do_stream+0x52>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1265 <do_stream+0xf5>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
mov    %rbx,%rcx
call   1090 <getdelim@plt>
test   %rax,%rax
jle    1241 <do_stream+0xd1>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
mov    %rbx,%rcx
call   1090 <getdelim@plt>
test   %rax,%rax
jg     1200 <do_stream+0x90>
mov    $0x1,%ebp
cmp    0x0(%r13),%rbx
je     1254 <do_stream+0xe4>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1080 <perror@plt>
xor    %ebp,%ebp
jmp    1254 <do_stream+0xe4>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @do_stream(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i32*, i32** @stdin
store i32* %9, i32** %4
%10 = load i32*, i32** @stdout
store i32* %10, i32** %5
%11 = load i8*, i8** %3
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @perror(i8* %20)
store i32 0, i32* %2
br label %44
22: ; preds = %14
br label %23
23: ; preds = %22, %1
br label %24
24: ; preds = %23, %30
store i8* null, i8** %6
store i64 0, i64* %7
%25 = load i32*, i32** %4
%26 = call i64 @getdelim(i8** %6, i64* %7, i8 signext 10, i32* %25)
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = icmp sle i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %36
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = load i32*, i32** %5
%33 = call i32 @fputs(i8* %31, i32* %32)
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
br label %24
36: ; preds = %29
%37 = load i32*, i32** %4
%38 = load i32*, i32** @stdin
%39 = icmp ne i32* %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %40, %36
store i32 1, i32* %2
br label %44
44: ; preds = %43, %19
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @do_stream(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = load i32*, i32** @stdin
%5 = load i32*, i32** @stdout
%6 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* %0)
br label %31
13: ; preds = %8, %1
%14 = phi i32* [ %9, %8 ], [ %4, %1 ]
%15 = bitcast i8** %2 to i8*
%16 = bitcast i64* %3 to i8*
store i8* null, i8** %2
store i64 0, i64* %3
%17 = call i64 @getdelim(i8** %2, i64* %3, i8 signext 10, i32* %14)
%18 = icmp slt i64 %17, 1
br i1 %18, label %26, label %19
19: ; preds = %13, %19
%20 = load i8*, i8** %2
%21 = call i32 @fputs(i8* %20, i32* %5)
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
store i8* null, i8** %2
store i64 0, i64* %3
%24 = call i64 @getdelim(i8** %2, i64* %3, i8 signext 10, i32* %14)
%25 = icmp slt i64 %24, 1
br i1 %25, label %26, label %19
26: ; preds = %19, %13
%27 = load i32*, i32** @stdin
%28 = icmp eq i32* %14, %27
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @fclose(i32* %14)
br label %31
31: ; preds = %26, %29, %11
%32 = phi i32 [ 0, %11 ], [ 1, %29 ], [ 1, %26 ]
ret i32 %32
}