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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ get_line_queue(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ piece_multiple(char *, int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void *strdup(char *);
int /*<<< orphan*/ unget_line_queue(char *);
int timlib_get_block_delimiter(char **block, int delimiter,
                               int columns_to_block, FILE *input_file,
                               int max_lines) {
  char buffer[131072];
  char first_field[1024];
  char old_first_field[1024];
  int count = 0;
  *old_first_field = '\0';
  while (get_line_queue(buffer, input_file)) {
    if (count == max_lines) {
      fprintf(stderr,
              "ERROR in get_block_delimiter: max lines of %d exceeded\n",
              max_lines);
      exit(1);
    }
    count++;
    piece_multiple(first_field, delimiter, buffer, columns_to_block);
    if (!*old_first_field) {
      strcpy(old_first_field, first_field);
      *block++ = strdup(buffer);
    } else {
      if (strcmp(old_first_field, first_field) != 0) {
        unget_line_queue(buffer);
        return count - 1;
      } else {
        *block++ = strdup(buffer);
      }
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<timlib_get_block_delimiter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x20834(%rbp)
movb   $0x0,-0x20830(%rbp)
lea    -0x20030(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <get_line_queue@plt>
cmp    $0x0,%rax
je     12cc <timlib_get_block_delimiter+0x14c>
mov    -0x20834(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11f9 <timlib_get_block_delimiter+0x79>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20834(%rbp)
lea    -0x20430(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x20030(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1080 <piece_multiple@plt>
cmpb   $0x0,-0x20830(%rbp)
jne    1267 <timlib_get_block_delimiter+0xe7>
lea    -0x20830(%rbp),%rdi
lea    -0x20430(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x20030(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
jmp    12c7 <timlib_get_block_delimiter+0x147>
lea    -0x20830(%rbp),%rdi
lea    -0x20430(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     12a1 <timlib_get_block_delimiter+0x121>
lea    -0x20030(%rbp),%rdi
call   1070 <unget_line_queue@plt>
mov    -0x20834(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12d5 <timlib_get_block_delimiter+0x155>
lea    -0x20030(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
jmp    12c7 <timlib_get_block_delimiter+0x147>
jmp    11ae <timlib_get_block_delimiter+0x2e>
mov    -0x20834(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timlib_get_block_delimiter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20818,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %edx,0x4(%rsp)
mov    %esi,%r13d
mov    %rdi,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x810(%rsp),%rdi
mov    %rcx,%rsi
call   1060 <get_line_queue@plt>
test   %rax,%rax
je     1250 <timlib_get_block_delimiter+0xd0>
mov    %ebx,%ebp
xor    %ebx,%ebx
lea    0x410(%rsp),%r15
lea    0x810(%rsp),%r12
jmp    1212 <timlib_get_block_delimiter+0x92>
nopw   0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   10a0 <strdup@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx,%rbx,8)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <get_line_queue@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1252 <timlib_get_block_delimiter+0xd2>
cmp    %ebx,%ebp
je     1266 <timlib_get_block_delimiter+0xe6>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r12,%rdx
mov    0x4(%rsp),%ecx
call   1080 <piece_multiple@plt>
cmpb   $0x0,0x10(%rsp)
je     11e0 <timlib_get_block_delimiter+0x60>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ed <timlib_get_block_delimiter+0x6d>
lea    0x810(%rsp),%rdi
call   1070 <unget_line_queue@plt>
jmp    1252 <timlib_get_block_delimiter+0xd2>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"ERROR in get_block_delimiter: max lines of %d exceeded\0A\00"
define i32 @timlib_get_block_delimiter(i8** %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [131072 x i8]
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
%15 = alloca i32
store i8** %0, i8*** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32 0, i32* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
store i8 0, i8* %16
br label %17
17: ; preds = %66, %5
%18 = getelementptr inbounds [131072 x i8], [131072 x i8]* %12, i64 0, i64 0
%19 = load i32*, i32** %10
%20 = call i64 @get_line_queue(i8* %18, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %67
22: ; preds = %17
%23 = load i32, i32* %15
%24 = load i32, i32* %11
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32, i32* %11
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %15
%33 = add nsw i32 %32, 1
store i32 %33, i32* %15
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%35 = load i32, i32* %8
%36 = getelementptr inbounds [131072 x i8], [131072 x i8]* %12, i64 0, i64 0
%37 = load i32, i32* %9
%38 = call i32 @piece_multiple(i8* %34, i32 %35, i8* %36, i32 %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %50, label %42
42: ; preds = %31
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = getelementptr inbounds [131072 x i8], [131072 x i8]* %12, i64 0, i64 0
%47 = call i8* @strdup(i8* %46)
%48 = load i8**, i8*** %7
%49 = getelementptr inbounds i8*, i8** %48, i32 1
store i8** %49, i8*** %7
store i8* %47, i8** %48
br label %66
50: ; preds = %31
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%53 = call i64 @strcmp(i8* %51, i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = getelementptr inbounds [131072 x i8], [131072 x i8]* %12, i64 0, i64 0
%57 = call i32 @unget_line_queue(i8* %56)
%58 = load i32, i32* %15
%59 = sub nsw i32 %58, 1
store i32 %59, i32* %6
br label %69
60: ; preds = %50
%61 = getelementptr inbounds [131072 x i8], [131072 x i8]* %12, i64 0, i64 0
%62 = call i8* @strdup(i8* %61)
%63 = load i8**, i8*** %7
%64 = getelementptr inbounds i8*, i8** %63, i32 1
store i8** %64, i8*** %7
store i8* %62, i8** %63
br label %65
65: ; preds = %60
br label %66
66: ; preds = %65, %42
br label %17
67: ; preds = %17
%68 = load i32, i32* %15
store i32 %68, i32* %6
br label %69
69: ; preds = %67, %55
%70 = load i32, i32* %6
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"ERROR in get_block_delimiter: max lines of %d exceeded\0A\00"
define i32 @timlib_get_block_delimiter(i8** nocapture writeonly %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca [131072 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = getelementptr inbounds [131072 x i8], [131072 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %11
%12 = call i64 @get_line_queue(i8* %9, i32* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %5, %34
%15 = phi i32 [ %23, %34 ], [ 0, %5 ]
%16 = phi i8** [ %36, %34 ], [ %0, %5 ]
%17 = icmp eq i32 %15, %4
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %4)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = add nuw nsw i32 %15, 1
%24 = call i32 @piece_multiple(i8* %10, i32 %1, i8* %9, i32 %2)
%25 = load i8, i8* %11
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @strcpy(i8* %11, i8* %10)
br label %34
29: ; preds = %22
%30 = call i64 @strcmp(i8* %11, i8* %10)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @unget_line_queue(i8* %9)
br label %39
34: ; preds = %29, %27
%35 = call i8* @strdup(i8* %9)
%36 = getelementptr inbounds i8*, i8** %16, i64 1
store i8* %35, i8** %16
%37 = call i64 @get_line_queue(i8* %9, i32* %3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %14
39: ; preds = %34, %5, %32
%40 = phi i32 [ %15, %32 ], [ 0, %5 ], [ %23, %34 ]
ret i32 %40
}