#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*/ lprintf(int, char *, ...);
char *stream_getln(struct stream *, int /*<<< orphan*/ *);
void print_stream(struct stream *s) {
  char *line;
  line = stream_getln(s, NULL);
  while (line != NULL) {
    lprintf(-1, "%s\n", line);
    line = stream_getln(s, NULL);
  }
  lprintf(-1, "\n");
}


x86 assembly (clang, -O0):
<print_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <stream_getln@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1175 <print_stream+0x55>
mov    -0x10(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1040 <lprintf@plt>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <stream_getln@plt>
mov    %rax,-0x10(%rbp)
jmp    113d <print_stream+0x1d>
mov    $0xffffffff,%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <lprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stream>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
call   1030 <stream_getln@plt>
test   %rax,%rax
je     1161 <print_stream+0x41>
lea    0xec6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    $0xffffffff,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <lprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <stream_getln@plt>
test   %rax,%rax
jne    1140 <print_stream+0x20>
lea    0xe9a(%rip),%rsi
mov    $0xffffffff,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <lprintf@plt>

LLVM IR (-O0):
%struct.stream = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_stream(%struct.stream* %0) {
%2 = alloca %struct.stream*
%3 = alloca i8*
store %struct.stream* %0, %struct.stream** %2
%4 = load %struct.stream*, %struct.stream** %2
%5 = call i8* @stream_getln(%struct.stream* %4, i32* null)
store i8* %5, i8** %3
br label %6
6: ; preds = %9, %1
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = call i32 (i32, i8*, ...) @lprintf(i32 -1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load %struct.stream*, %struct.stream** %2
%13 = call i8* @stream_getln(%struct.stream* %12, i32* null)
store i8* %13, i8** %3
br label %6
14: ; preds = %6
%15 = call i32 (i32, i8*, ...) @lprintf(i32 -1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.stream = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_stream(%struct.stream* %0) {
%2 = tail call i8* @stream_getln(%struct.stream* %0, i32* null)
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %7, %4 ], [ %2, %1 ]
%6 = tail call i32 (i32, i8*, ...) @lprintf(i32 -1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i8* @stream_getln(%struct.stream* %0, i32* null)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %4
9: ; preds = %4, %1
%10 = tail call i32 (i32, i8*, ...) @lprintf(i32 -1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}