#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 sentence {
  int dummy;
};
struct blocks {
  int dummy;
};
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ blocks_add_elem(struct blocks *, char *);
int /*<<< orphan*/ destroy_blocks(struct blocks *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(char const **);
int /*<<< orphan*/ latex_print_dep_tree(struct sentence *);
struct blocks *new_blocks(int);
int /*<<< orphan*/ sentence_add_token(struct sentence *, int /*<<< orphan*/);
int /*<<< orphan*/ sentence_destroy(struct sentence *);
struct sentence *sentence_new();
int /*<<< orphan*/ stderr;
char *strndup(char *, size_t);
size_t strnlen(char *, int);
char *strsep(char **, char const *);
int /*<<< orphan*/ token_new(char const **, int);
char **xmalloc(int);
int read_conllx(FILE *fp) {
  int num_sent = 0;
  unsigned int line_num = 0;
  char buff[8192];
  const char *sep = "\t";
  char *t, *line, *tofree;
  size_t len;
  const char **seq = xmalloc(sizeof(char *) * 10);
  struct blocks *blocks = new_blocks(256);
  struct sentence *sent = sentence_new();
  while (fgets(buff, sizeof(buff), fp)) {
    line_num++;
    if (buff[0] == '\n') {
      latex_print_dep_tree(sent);
      sentence_destroy(sent);
      sent = sentence_new();
      num_sent++;
      continue;
    }
    len = strnlen(buff, 8192);
    tofree = line = strndup(buff, len - 1);
    blocks_add_elem(blocks, tofree);
    int i = 0;
    while ((t = strsep(&line, sep)) != NULL) {
      seq[i] = t;
      i++;
    }
    sentence_add_token(sent, token_new(seq, 10));
  }
  destroy_blocks(blocks);
  sentence_destroy(sent);
  free(seq);
  fprintf(stderr, "INFO: Number of sentences = %d\n", num_sent);
  return 0;
}


x86 assembly (clang, -O0):
<read_conllx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xdec(%rip),%rax
mov    %rax,-0x2018(%rbp)
mov    $0x50,%edi
call   1080 <xmalloc@plt>
mov    %rax,-0x2040(%rbp)
mov    $0x100,%edi
call   1100 <new_blocks@plt>
mov    %rax,-0x2048(%rbp)
mov    $0x0,%al
call   10f0 <sentence_new@plt>
mov    %rax,-0x2050(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     1394 <read_conllx+0x1a4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x2010(%rbp),%eax
cmp    $0xa,%eax
jne    12b7 <read_conllx+0xc7>
mov    -0x2050(%rbp),%rdi
call   1040 <latex_print_dep_tree@plt>
mov    -0x2050(%rbp),%rdi
call   10c0 <sentence_destroy@plt>
mov    $0x0,%al
call   10f0 <sentence_new@plt>
mov    %rax,-0x2050(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    124b <read_conllx+0x5b>
lea    -0x2010(%rbp),%rdi
mov    $0x2000,%esi
call   1070 <strnlen@plt>
mov    %rax,-0x2038(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x2038(%rbp),%rsi
sub    $0x1,%rsi
call   1090 <strndup@plt>
mov    %rax,-0x2028(%rbp)
mov    %rax,-0x2030(%rbp)
mov    -0x2048(%rbp),%rdi
mov    -0x2030(%rbp),%rsi
call   1050 <blocks_add_elem@plt>
movl   $0x0,-0x2054(%rbp)
mov    -0x2018(%rbp),%rsi
lea    -0x2028(%rbp),%rdi
call   10d0 <strsep@plt>
mov    %rax,-0x2020(%rbp)
cmp    $0x0,%rax
je     1362 <read_conllx+0x172>
mov    -0x2020(%rbp),%rdx
mov    -0x2040(%rbp),%rax
movslq -0x2054(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2054(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2054(%rbp)
jmp    1311 <read_conllx+0x121>
mov    -0x2050(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    -0x2040(%rbp),%rdi
mov    $0xa,%esi
call   1110 <token_new@plt>
mov    -0x2060(%rbp),%rdi
mov    %eax,%esi
call   10e0 <sentence_add_token@plt>
jmp    124b <read_conllx+0x5b>
mov    -0x2048(%rbp),%rdi
call   1060 <destroy_blocks@plt>
mov    -0x2050(%rbp),%rdi
call   10c0 <sentence_destroy@plt>
mov    -0x2040(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xc37(%rip),%rsi
call   10b0 <fprintf@plt>
xor    %eax,%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_conllx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
mov    %rdi,%rbx
mov    $0x50,%edi
call   1080 <xmalloc@plt>
mov    %rax,%r12
mov    $0x100,%edi
call   1100 <new_blocks@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   10f0 <sentence_new@plt>
mov    %rax,%r13
lea    0x20(%rsp),%rdi
mov    $0x2000,%esi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     132c <read_conllx+0x13c>
lea    0x20(%rsp),%rbp
lea    0xdaa(%rip),%r14
lea    0x18(%rsp),%r15
movl   $0x0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,0x20(%rsp)
je     130b <read_conllx+0x11b>
mov    %rbp,%rdi
mov    $0x2000,%esi
call   1070 <strnlen@plt>
lea    -0x1(%rax),%rsi
mov    %rbp,%rdi
call   1090 <strndup@plt>
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%rdi
mov    %rax,%rsi
call   1050 <blocks_add_elem@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <strsep@plt>
test   %rax,%rax
je     12d7 <read_conllx+0xe7>
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %rax,(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <strsep@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    12c0 <read_conllx+0xd0>
mov    %r12,%rdi
mov    $0xa,%esi
call   1110 <token_new@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   10e0 <sentence_add_token@plt>
mov    %rbp,%rdi
mov    $0x2000,%esi
mov    0x8(%rsp),%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1270 <read_conllx+0x80>
jmp    1334 <read_conllx+0x144>
mov    %r13,%rdi
call   1040 <latex_print_dep_tree@plt>
mov    %r13,%rdi
call   10c0 <sentence_destroy@plt>
xor    %eax,%eax
call   10f0 <sentence_new@plt>
mov    %rax,%r13
addl   $0x1,0x4(%rsp)
jmp    12ee <read_conllx+0xfe>
movl   $0x0,0x4(%rsp)
mov    0x10(%rsp),%rdi
call   1060 <destroy_blocks@plt>
mov    %r13,%rdi
call   10c0 <sentence_destroy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
lea    0xca4(%rip),%rsi
mov    0x4(%rsp),%edx
call   10b0 <fprintf@plt>
xor    %eax,%eax
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.blocks = type { i32 }
%struct.sentence = type { i32 }
@.str = [2 x i8] c"\09\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"INFO: Number of sentences = %d\0A\00"
define i32 @read_conllx(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8192 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8**
%12 = alloca %struct.blocks*
%13 = alloca %struct.sentence*
%14 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%15 = call i8** @xmalloc(i32 80)
store i8** %15, i8*** %11
%16 = call %struct.blocks* @new_blocks(i32 256)
store %struct.blocks* %16, %struct.blocks** %12
%17 = call %struct.sentence* (...) @sentence_new()
store %struct.sentence* %17, %struct.sentence** %13
br label %18
18: ; preds = %60, %30, %1
%19 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %2
%21 = call i64 @fgets(i8* %19, i32 8192, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %65
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add i32 %24, 1
store i32 %25, i32* %4
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %38
30: ; preds = %23
%31 = load %struct.sentence*, %struct.sentence** %13
%32 = call i32 @latex_print_dep_tree(%struct.sentence* %31)
%33 = load %struct.sentence*, %struct.sentence** %13
%34 = call i32 @sentence_destroy(%struct.sentence* %33)
%35 = call %struct.sentence* (...) @sentence_new()
store %struct.sentence* %35, %struct.sentence** %13
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %18
38: ; preds = %23
%39 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%40 = call i64 @strnlen(i8* %39, i32 8192)
store i64 %40, i64* %10
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%42 = load i64, i64* %10
%43 = sub i64 %42, 1
%44 = call i8* @strndup(i8* %41, i64 %43)
store i8* %44, i8** %8
store i8* %44, i8** %9
%45 = load %struct.blocks*, %struct.blocks** %12
%46 = load i8*, i8** %9
%47 = call i32 @blocks_add_elem(%struct.blocks* %45, i8* %46)
store i32 0, i32* %14
br label %48
48: ; preds = %52, %38
%49 = load i8*, i8** %6
%50 = call i8* @strsep(i8** %8, i8* %49)
store i8* %50, i8** %7
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %60
52: ; preds = %48
%53 = load i8*, i8** %7
%54 = load i8**, i8*** %11
%55 = load i32, i32* %14
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
store i8* %53, i8** %57
%58 = load i32, i32* %14
%59 = add nsw i32 %58, 1
store i32 %59, i32* %14
br label %48
60: ; preds = %48
%61 = load %struct.sentence*, %struct.sentence** %13
%62 = load i8**, i8*** %11
%63 = call i32 @token_new(i8** %62, i32 10)
%64 = call i32 @sentence_add_token(%struct.sentence* %61, i32 %63)
br label %18
65: ; preds = %18
%66 = load %struct.blocks*, %struct.blocks** %12
%67 = call i32 @destroy_blocks(%struct.blocks* %66)
%68 = load %struct.sentence*, %struct.sentence** %13
%69 = call i32 @sentence_destroy(%struct.sentence* %68)
%70 = load i8**, i8*** %11
%71 = call i32 @free(i8** %70)
%72 = load i32, i32* @stderr
%73 = load i32, i32* %3
%74 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %73)
ret i32 0
}

LLVM IR (-O2):
%struct.blocks = type { i32 }
%struct.sentence = type { i32 }
@.str = [2 x i8] c"\09\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"INFO: Number of sentences = %d\0A\00"
define i32 @read_conllx(i32* nocapture %0) {
%2 = alloca [8192 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
%6 = tail call i8** @xmalloc(i32 80)
%7 = tail call %struct.blocks* @new_blocks(i32 256)
%8 = tail call %struct.sentence* (...) @sentence_new()
%9 = call i64 @fgets(i8* %4, i32 8192, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %43, label %11
11: ; preds = %1, %17
%12 = phi %struct.sentence* [ %20, %17 ], [ %8, %1 ]
%13 = phi i32 [ %21, %17 ], [ 0, %1 ]
br label %14
14: ; preds = %11, %38
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = call i32 @latex_print_dep_tree(%struct.sentence* %12)
%19 = call i32 @sentence_destroy(%struct.sentence* %12)
%20 = call %struct.sentence* (...) @sentence_new()
%21 = add nuw nsw i32 %13, 1
%22 = call i64 @fgets(i8* %4, i32 8192, i32* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %43, label %11
24: ; preds = %14
%25 = call i64 @strnlen(i8* %4, i32 8192)
%26 = add i64 %25, -1
%27 = call i8* @strndup(i8* %4, i64 %26)
store i8* %27, i8** %3
%28 = call i32 @blocks_add_elem(%struct.blocks* %7, i8* %27)
%29 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %38, label %31
31: ; preds = %24, %31
%32 = phi i64 [ %35, %31 ], [ 0, %24 ]
%33 = phi i8* [ %36, %31 ], [ %29, %24 ]
%34 = getelementptr inbounds i8*, i8** %6, i64 %32
store i8* %33, i8** %34
%35 = add nuw i64 %32, 1
%36 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %31
38: ; preds = %31, %24
%39 = call i32 @token_new(i8** %6, i32 10)
%40 = call i32 @sentence_add_token(%struct.sentence* %12, i32 %39)
%41 = call i64 @fgets(i8* %4, i32 8192, i32* %0)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %14
43: ; preds = %17, %38, %1
%44 = phi i32 [ 0, %1 ], [ %13, %38 ], [ %21, %17 ]
%45 = phi %struct.sentence* [ %8, %1 ], [ %12, %38 ], [ %20, %17 ]
%46 = call i32 @destroy_blocks(%struct.blocks* %7)
%47 = call i32 @sentence_destroy(%struct.sentence* %45)
%48 = call i32 @free(i8** %6)
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %44)
ret i32 0
}