#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 buf {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ buf_append(struct buf *, int);
int getc(int /*<<< orphan*/ *);
void buf_read_until_newline(struct buf *b, FILE *fp) {
  int ch;
  for (;;) {
    ch = getc(fp);
    if (ch == EOF)
      break;
    buf_append(b, ch);
    if (ch == '\n' || ch == '\r')
      break;
  }
}


x86 assembly (clang, -O0):
<buf_read_until_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
jne    1153 <buf_read_until_newline+0x33>
jmp    117d <buf_read_until_newline+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <buf_append@plt>
cmpl   $0xa,-0x14(%rbp)
je     1173 <buf_read_until_newline+0x53>
cmpl   $0xd,-0x14(%rbp)
jne    1178 <buf_read_until_newline+0x58>
jmp    117d <buf_read_until_newline+0x5d>
jmp    1130 <buf_read_until_newline+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_read_until_newline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2eb4(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    (%r15),%eax
je     1163 <buf_read_until_newline+0x43>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <buf_append@plt>
cmp    $0xd,%ebp
je     1163 <buf_read_until_newline+0x43>
cmp    $0xa,%ebp
jne    1140 <buf_read_until_newline+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buf = type { i32 }
@EOF = global i32 0
define void @buf_read_until_newline(%struct.buf* %0, i32* %1) {
%3 = alloca %struct.buf*
%4 = alloca i32*
%5 = alloca i32
store %struct.buf* %0, %struct.buf** %3
store i32* %1, i32** %4
br label %6
6: ; preds = %23, %2
%7 = load i32*, i32** %4
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %6
br label %24
13: ; preds = %6
%14 = load %struct.buf*, %struct.buf** %3
%15 = load i32, i32* %5
%16 = call i32 @buf_append(%struct.buf* %14, i32 %15)
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 10
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 13
br i1 %21, label %22, label %23
22: ; preds = %19, %13
br label %24
23: ; preds = %19
br label %6
24: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
%struct.buf = type { i32 }
@EOF = global i32 0
define void @buf_read_until_newline(%struct.buf* %0, i32* nocapture %1) {
br label %3
3: ; preds = %7, %2
%4 = tail call i32 @getc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @buf_append(%struct.buf* %0, i32 %4)
switch i32 %4, label %3 [
i32 13, label %9
i32 10, label %9
]
9: ; preds = %7, %7, %3
ret void
}