#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 EOF;
int fgetc(int /*<<< orphan*/ *);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(long *, int, int, int /*<<< orphan*/ *);
void indexfile(FILE *in, FILE *out) {
  int ch, ch0, ch1;
  long pos;
  pos = 0;
  ch0 = 0;
  ch1 = 0;
  while ((ch = fgetc(in)) != EOF) {
    if ((ch1 == '\n' || ch1 == 0) && ch0 == '%' && ch == '\n') {
      fwrite(&pos, 1, sizeof pos, out);
      pos = ftell(in);
    }
    ch1 = ch0;
    ch0 = ch;
  }
  fwrite(&pos, 1, sizeof pos, out);
}


x86 assembly (clang, -O0):
<indexfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
je     11ce <indexfile+0x9e>
cmpl   $0xa,-0x1c(%rbp)
je     1185 <indexfile+0x55>
cmpl   $0x0,-0x1c(%rbp)
jne    11bd <indexfile+0x8d>
cmpl   $0x25,-0x18(%rbp)
jne    11bd <indexfile+0x8d>
cmpl   $0xa,-0x14(%rbp)
jne    11bd <indexfile+0x8d>
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
call   1050 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1156 <indexfile+0x26>
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
call   1050 <fwrite@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
movq   $0x0,(%rsp)
call   1030 <fgetc@plt>
mov    0x2e93(%rip),%r12
cmp    (%r12),%eax
jne    117f <indexfile+0x4f>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
mov    %rsp,%r15
xor    %ebp,%ebp
jmp    11a0 <indexfile+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %ebx,%ecx
cmp    (%r12),%eax
je     115b <indexfile+0x2b>
mov    %ebp,%ebx
mov    %eax,%ebp
cmp    $0xa,%ecx
sete   %al
test   %ecx,%ecx
sete   %cl
cmp    $0xa,%ebp
jne    1190 <indexfile+0x60>
cmp    $0x25,%ebx
jne    1190 <indexfile+0x60>
or     %cl,%al
je     1190 <indexfile+0x60>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
mov    %r13,%rdi
call   1040 <ftell@plt>
mov    %rax,(%rsp)
jmp    1190 <indexfile+0x60>

LLVM IR (-O0):
@EOF = global i32 0
define void @indexfile(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i64 0, i64* %8
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %31, %2
%10 = load i32*, i32** %3
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %9
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 10
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17, %14
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 37
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = call i32 @fwrite(i64* %8, i32 1, i32 8, i32* %27)
%29 = load i32*, i32** %3
%30 = call i64 @ftell(i32* %29)
store i64 %30, i64* %8
br label %31
31: ; preds = %26, %23, %20, %17
%32 = load i32, i32* %6
store i32 %32, i32* %7
%33 = load i32, i32* %5
store i32 %33, i32* %6
br label %9
34: ; preds = %9
%35 = load i32*, i32** %4
%36 = call i32 @fwrite(i64* %8, i32 1, i32 8, i32* %35)
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @indexfile(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = tail call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %26, label %8
8: ; preds = %2, %22
%9 = phi i32 [ %23, %22 ], [ %5, %2 ]
%10 = phi i32 [ %11, %22 ], [ 0, %2 ]
%11 = phi i32 [ %9, %22 ], [ 0, %2 ]
%12 = icmp eq i32 %10, 10
%13 = icmp eq i32 %10, 0
%14 = or i1 %12, %13
%15 = icmp eq i32 %11, 37
%16 = and i1 %15, %14
%17 = icmp eq i32 %9, 10
%18 = and i1 %17, %16
br i1 %18, label %19, label %22
19: ; preds = %8
%20 = call i32 @fwrite(i64* %3, i32 1, i32 8, i32* %1)
%21 = tail call i64 @ftell(i32* %0)
store i64 %21, i64* %3
br label %22
22: ; preds = %8, %19
%23 = tail call i32 @fgetc(i32* %0)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %8
26: ; preds = %22, %2
%27 = call i32 @fwrite(i64* %3, i32 1, i32 8, i32* %1)
ret void
}