#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 */
scalar_t__ AddTextFile(char *, int /*<<< orphan*/ *, int);
scalar_t__ ParseListFileLine(char *, char **, int *);
int /*<<< orphan*/ SEEK_SET;
scalar_t__ SetCurrentHlpFilePosition(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ TrimBuffer(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int MoveTextFiles(FILE *ifptr, FILE *ofptr) {
  char buffer[1024];
  char *result, *file;
  int pagenum = 0;
  fseek(ifptr, 0, SEEK_SET);
  for (;;) {
    result = fgets(buffer, 1024, ifptr);
    if (!result)
      break;
    TrimBuffer(buffer);
    if (buffer[0] != '\0') {
      if (ParseListFileLine(buffer, &file, &pagenum))
        return 1;
      if (SetCurrentHlpFilePosition(ofptr, pagenum, 0))
        return 1;
      if (AddTextFile(file, ofptr, pagenum))
        return 1;
      if (SetCurrentHlpFilePosition(ofptr, pagenum, 1))
        return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<MoveTextFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x434(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11c0 <MoveTextFiles+0x60>
jmp    1293 <MoveTextFiles+0x133>
lea    -0x420(%rbp),%rdi
call   1040 <TrimBuffer@plt>
movsbl -0x420(%rbp),%eax
cmp    $0x0,%eax
je     128e <MoveTextFiles+0x12e>
lea    -0x420(%rbp),%rdi
lea    -0x430(%rbp),%rsi
lea    -0x434(%rbp),%rdx
call   1060 <ParseListFileLine@plt>
cmp    $0x0,%rax
je     120c <MoveTextFiles+0xac>
movl   $0x1,-0x4(%rbp)
jmp    129a <MoveTextFiles+0x13a>
mov    -0x18(%rbp),%rdi
mov    -0x434(%rbp),%esi
xor    %edx,%edx
call   1030 <SetCurrentHlpFilePosition@plt>
cmp    $0x0,%rax
je     1233 <MoveTextFiles+0xd3>
movl   $0x1,-0x4(%rbp)
jmp    129a <MoveTextFiles+0x13a>
mov    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   1070 <AddTextFile@plt>
cmp    $0x0,%rax
je     125f <MoveTextFiles+0xff>
movl   $0x1,-0x4(%rbp)
jmp    129a <MoveTextFiles+0x13a>
mov    -0x18(%rbp),%rdi
mov    -0x434(%rbp),%esi
mov    $0x1,%edx
call   1030 <SetCurrentHlpFilePosition@plt>
cmp    $0x0,%rax
je     1289 <MoveTextFiles+0x129>
movl   $0x1,-0x4(%rbp)
jmp    129a <MoveTextFiles+0x13a>
jmp    128e <MoveTextFiles+0x12e>
jmp    1191 <MoveTextFiles+0x31>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MoveTextFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1244 <MoveTextFiles+0xe4>
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
jmp    11d5 <MoveTextFiles+0x75>
nopl   (%rax)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1242 <MoveTextFiles+0xe2>
mov    %r15,%rdi
call   1040 <TrimBuffer@plt>
cmpb   $0x0,0x10(%rsp)
je     11c0 <MoveTextFiles+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <ParseListFileLine@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1244 <MoveTextFiles+0xe4>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <SetCurrentHlpFilePosition@plt>
test   %rax,%rax
jne    1244 <MoveTextFiles+0xe4>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%edx
mov    %rbx,%rsi
call   1070 <AddTextFile@plt>
test   %rax,%rax
jne    1244 <MoveTextFiles+0xe4>
mov    0x4(%rsp),%esi
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <SetCurrentHlpFilePosition@plt>
test   %rax,%rax
je     11c0 <MoveTextFiles+0x60>
jmp    1244 <MoveTextFiles+0xe4>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @MoveTextFiles(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %9
%10 = load i32*, i32** %4
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %10, i32 0, i32 %11)
br label %13
13: ; preds = %52, %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i8* @fgets(i8* %14, i32 1024, i32* %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %13
br label %53
20: ; preds = %13
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i32 @TrimBuffer(i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %52
27: ; preds = %20
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i64 @ParseListFileLine(i8* %28, i8** %8, i32* %9)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %3
br label %54
32: ; preds = %27
%33 = load i32*, i32** %5
%34 = load i32, i32* %9
%35 = call i64 @SetCurrentHlpFilePosition(i32* %33, i32 %34, i32 0)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %3
br label %54
38: ; preds = %32
%39 = load i8*, i8** %8
%40 = load i32*, i32** %5
%41 = load i32, i32* %9
%42 = call i64 @AddTextFile(i8* %39, i32* %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %3
br label %54
45: ; preds = %38
%46 = load i32*, i32** %5
%47 = load i32, i32* %9
%48 = call i64 @SetCurrentHlpFilePosition(i32* %46, i32 %47, i32 1)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 1, i32* %3
br label %54
51: ; preds = %45
br label %52
52: ; preds = %51, %20
br label %13
53: ; preds = %19
store i32 0, i32* %3
br label %54
54: ; preds = %53, %50, %44, %37, %31
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @MoveTextFiles(i32* nocapture %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %0, i32 0, i32 %9)
%11 = call i8* @fgets(i8* %6, i32 1024, i32* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %36, label %13
13: ; preds = %2, %33
%14 = call i32 @TrimBuffer(i8* %6)
%15 = load i8, i8* %6
%16 = icmp eq i8 %15, 0
br i1 %16, label %33, label %17
17: ; preds = %13
%18 = call i64 @ParseListFileLine(i8* %6, i8** %4, i32* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i32, i32* %5
%22 = call i64 @SetCurrentHlpFilePosition(i32* %1, i32 %21, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = call i64 @AddTextFile(i8* %25, i32* %1, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i32, i32* %5
%31 = call i64 @SetCurrentHlpFilePosition(i32* %1, i32 %30, i32 1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29, %13
%34 = call i8* @fgets(i8* %6, i32 1024, i32* %0)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %13
36: ; preds = %17, %20, %24, %29, %33, %2
%37 = phi i32 [ 0, %2 ], [ 0, %33 ], [ 1, %29 ], [ 1, %24 ], [ 1, %20 ], [ 1, %17 ]
ret i32 %37
}