#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 scanner {
  int dummy;
};
struct corpus {
  int dummy;
};
typedef int /*<<< orphan*/ b;

/* Variables and functions */
scalar_t__ add_sentence(struct corpus *, char *);
int /*<<< orphan*/ scanner_free(struct scanner *);
struct scanner *scanner_open(char const *);
scalar_t__ scanner_readline(struct scanner *, char *, int);
int corpus_parse(struct corpus *c, const char *path) {
  struct scanner *s;
  char b[8192] = {0};
  s = scanner_open(path);
  if (s == NULL)
    return -1;
  while (scanner_readline(s, b, sizeof(b)) >= 0) {
    if (*b)
      if (add_sentence(c, b) != 0)
        return -1;
  }
  scanner_free(s);
  return 0;
}


x86 assembly (clang, -O0):
<corpus_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1070 <scanner_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <corpus_parse+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <corpus_parse+0xbb>
jmp    119f <corpus_parse+0x4f>
mov    -0x20(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <scanner_readline@plt>
cmp    $0x0,%rax
jl     11fb <corpus_parse+0xab>
cmpb   $0x0,-0x2020(%rbp)
je     11f6 <corpus_parse+0xa6>
mov    -0x10(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
call   1060 <add_sentence@plt>
cmp    $0x0,%rax
je     11f1 <corpus_parse+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <corpus_parse+0xbb>
jmp    11f6 <corpus_parse+0xa6>
jmp    119f <corpus_parse+0x4f>
mov    -0x20(%rbp),%rdi
call   1040 <scanner_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<corpus_parse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1070 <scanner_open@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11e8 <corpus_parse+0x98>
mov    %rax,%rbp
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x2000,%edx
call   1030 <scanner_readline@plt>
test   %rax,%rax
js     11dd <corpus_parse+0x8d>
mov    %rsp,%rbx
jmp    11c5 <corpus_parse+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1030 <scanner_readline@plt>
test   %rax,%rax
js     11dd <corpus_parse+0x8d>
cmpb   $0x0,(%rsp)
je     11b0 <corpus_parse+0x60>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <add_sentence@plt>
test   %rax,%rax
je     11b0 <corpus_parse+0x60>
jmp    11e8 <corpus_parse+0x98>
mov    %rbp,%rdi
call   1040 <scanner_free@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.corpus = type { i32 }
%struct.scanner = type { i32 }
define i32 @corpus_parse(%struct.corpus* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.corpus*
%5 = alloca i8*
%6 = alloca %struct.scanner*
%7 = alloca [8192 x i8]
store %struct.corpus* %0, %struct.corpus** %4
store i8* %1, i8** %5
%8 = bitcast [8192 x i8]* %7 to i8*
%9 = load i8*, i8** %5
%10 = call %struct.scanner* @scanner_open(i8* %9)
store %struct.scanner* %10, %struct.scanner** %6
%11 = load %struct.scanner*, %struct.scanner** %6
%12 = icmp eq %struct.scanner* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %35
14: ; preds = %2
br label %15
15: ; preds = %31, %14
%16 = load %struct.scanner*, %struct.scanner** %6
%17 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%18 = call i64 @scanner_readline(%struct.scanner* %16, i8* %17, i32 8192)
%19 = icmp sge i64 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load %struct.corpus*, %struct.corpus** %4
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%27 = call i64 @add_sentence(%struct.corpus* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %3
br label %35
30: ; preds = %24
br label %31
31: ; preds = %30, %20
br label %15
32: ; preds = %15
%33 = load %struct.scanner*, %struct.scanner** %6
%34 = call i32 @scanner_free(%struct.scanner* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %32, %29, %13
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.corpus = type { i32 }
%struct.scanner = type { i32 }
define i32 @corpus_parse(%struct.corpus* %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = tail call %struct.scanner* @scanner_open(i8* %1)
%6 = icmp eq %struct.scanner* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = call i64 @scanner_readline(%struct.scanner* %5, i8* %4, i32 8192)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %7, %16
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i64 @add_sentence(%struct.corpus* %0, i8* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13, %10
%17 = call i64 @scanner_readline(%struct.scanner* %5, i8* %4, i32 8192)
%18 = icmp sgt i64 %17, -1
br i1 %18, label %10, label %19
19: ; preds = %16, %7
%20 = call i32 @scanner_free(%struct.scanner* %5)
br label %21
21: ; preds = %13, %2, %19
%22 = phi i32 [ 0, %19 ], [ -1, %2 ], [ -1, %13 ]
ret i32 %22
}