#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 string {
  int dummy;
};
struct buffer {
  int dummy;
};

/* Variables and functions */
scalar_t__ buffer_data_available(struct buffer *);
char buffer_getchar(struct buffer *);
int /*<<< orphan*/ string_append_char(struct string *, char);
int /*<<< orphan*/ string_clear(struct string *);
int load_line(struct buffer *buffer, struct string *line) {
  int escape = 0;
  int comment = 0;
  int success = 0;
  string_clear(line);
  while (buffer_data_available(buffer)) {
    char c = buffer_getchar(buffer);
    if (c == '\n' && !escape) {
      success = 1;
      break;
    }
    if (c == '#') {
      comment = 1;
    }
    if (!comment) {
      string_append_char(line, c);
    }
    escape = (c == '\\');
  }
  return (success);
}


x86 assembly (clang, -O0):
<load_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <string_clear@plt>
mov    -0x8(%rbp),%rdi
call   1030 <buffer_data_available@plt>
cmp    $0x0,%rax
je     11f2 <load_line+0xb2>
mov    -0x8(%rbp),%rdi
call   1050 <buffer_getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    11b0 <load_line+0x70>
cmpl   $0x0,-0x14(%rbp)
jne    11b0 <load_line+0x70>
movl   $0x1,-0x1c(%rbp)
jmp    11f2 <load_line+0xb2>
movsbl -0x1d(%rbp),%eax
cmp    $0x23,%eax
jne    11c4 <load_line+0x84>
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11db <load_line+0x9b>
mov    -0x10(%rbp),%rdi
movsbl -0x1d(%rbp),%esi
call   1040 <string_append_char@plt>
movsbl -0x1d(%rbp),%eax
cmp    $0x5c,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <load_line+0x2e>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1060 <string_clear@plt>
mov    %r12,%rdi
call   1030 <buffer_data_available@plt>
test   %rax,%rax
je     11cd <load_line+0x8d>
xor    %ebp,%ebp
mov    $0x1,%r15d
xor    %r13d,%r13d
jmp    11a2 <load_line+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x23,%bl
cmove  %r15d,%r13d
test   %r13d,%r13d
je     11c0 <load_line+0x80>
xor    %ebp,%ebp
cmp    $0x5c,%bl
sete   %bpl
mov    %r12,%rdi
call   1030 <buffer_data_available@plt>
test   %rax,%rax
je     11cd <load_line+0x8d>
mov    %r12,%rdi
call   1050 <buffer_getchar@plt>
mov    %eax,%ebx
cmp    $0xa,%al
jne    1180 <load_line+0x40>
test   %ebp,%ebp
jne    1180 <load_line+0x40>
jmp    11d0 <load_line+0x90>
cs nopw 0x0(%rax,%rax,1)
movsbl %bl,%esi
mov    %r14,%rdi
call   1040 <string_append_char@plt>
jmp    118c <load_line+0x4c>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
%struct.string = type { i32 }
define i32 @load_line(%struct.buffer* %0, %struct.string* %1) {
%3 = alloca %struct.buffer*
%4 = alloca %struct.string*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store %struct.buffer* %0, %struct.buffer** %3
store %struct.string* %1, %struct.string** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load %struct.string*, %struct.string** %4
%10 = call i32 @string_clear(%struct.string* %9)
br label %11
11: ; preds = %37, %2
%12 = load %struct.buffer*, %struct.buffer** %3
%13 = call i64 @buffer_data_available(%struct.buffer* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %42
15: ; preds = %11
%16 = load %struct.buffer*, %struct.buffer** %3
%17 = call signext i8 @buffer_getchar(%struct.buffer* %16)
store i8 %17, i8* %8
%18 = load i8, i8* %8
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %21
store i32 1, i32* %7
br label %42
25: ; preds = %21, %15
%26 = load i8, i8* %8
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 35
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 1, i32* %6
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load %struct.string*, %struct.string** %4
%35 = load i8, i8* %8
%36 = call i32 @string_append_char(%struct.string* %34, i8 signext %35)
br label %37
37: ; preds = %33, %30
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 92
%41 = zext i1 %40 to i32
store i32 %41, i32* %5
br label %11
42: ; preds = %24, %11
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
%struct.string = type { i32 }
define i32 @load_line(%struct.buffer* %0, %struct.string* %1) {
%3 = tail call i32 @string_clear(%struct.string* %1)
%4 = tail call i64 @buffer_data_available(%struct.buffer* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %21, %19 ], [ 0, %2 ]
%8 = phi i32 [ %15, %19 ], [ 0, %2 ]
%9 = tail call signext i8 @buffer_getchar(%struct.buffer* %0)
%10 = icmp ne i8 %9, 10
%11 = icmp ne i32 %7, 0
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %24
13: ; preds = %6
%14 = icmp eq i8 %9, 35
%15 = select i1 %14, i32 1, i32 %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @string_append_char(%struct.string* %1, i8 signext %9)
br label %19
19: ; preds = %13, %17
%20 = icmp eq i8 %9, 92
%21 = zext i1 %20 to i32
%22 = tail call i64 @buffer_data_available(%struct.buffer* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %6
24: ; preds = %19, %6, %2
%25 = phi i32 [ 0, %2 ], [ 1, %6 ], [ 0, %19 ]
ret i32 %25
}