#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 */

/* Variables and functions */
int next_int(char *);
int /*<<< orphan*/ printf(char *, int);
int init_tracks(char *file, char **trackp, int tracks) {
  char *save = file;
  while (file && next_int(file) != 0x4D54726B)
    file++;
  if (!file) {
    return 1;
  }
  trackp[0] = file + 8;
  printf("offset track1 %d\n", (int)(trackp[0] - save));
  for (int i = 1; i < tracks; i++) {
    file += 4;
    file += 4 + next_int(file);
    if (next_int(file) != 0x4D54726B)
      return 1;
    trackp[i] = file + 8;
  }
  return 0;
}


x86 assembly (clang, -O0):
<init_tracks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x2d(%rbp)
je     115f <init_tracks+0x3f>
mov    -0x10(%rbp),%rdi
call   1040 <next_int@plt>
cmp    $0x4d54726b,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    116f <init_tracks+0x4f>
jmp    1180 <init_tracks+0x60>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113b <init_tracks+0x1b>
cmpq   $0x0,-0x10(%rbp)
jne    1197 <init_tracks+0x77>
movl   $0x1,-0x4(%rbp)
jmp    1246 <init_tracks+0x126>
mov    -0x10(%rbp),%rcx
add    $0x8,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123f <init_tracks+0x11f>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <next_int@plt>
mov    %eax,%ecx
add    $0x4,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <next_int@plt>
cmp    $0x4d54726b,%eax
je     121d <init_tracks+0xfd>
movl   $0x1,-0x4(%rbp)
jmp    1246 <init_tracks+0x126>
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c9 <init_tracks+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_tracks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
test   %rdi,%rdi
je     11fe <init_tracks+0xde>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
add    $0x3,%rbp
mov    $0x7,%ebx
nopw   0x0(%rax,%rax,1)
lea    -0x3(%rbp),%rdi
call   1040 <next_int@plt>
add    $0x1,%ebx
add    $0x1,%rbp
cmp    $0x4d54726b,%eax
jne    1150 <init_tracks+0x30>
lea    0x4(%rbp),%rax
mov    %rax,(%r15)
lea    0xe8b(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
cmp    $0x2,%r14d
jl     11fe <init_tracks+0xde>
mov    %rbp,%rdi
call   1040 <next_int@plt>
cltq
add    %rax,%rbp
add    $0x4,%rbp
mov    %rbp,%rdi
call   1040 <next_int@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x4d54726b,%ecx
jne    11fe <init_tracks+0xde>
mov    %r14d,%r14d
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbx
lea    0x8(%rbp),%rax
mov    %rax,-0x8(%r15,%rcx,8)
cmp    %rcx,%r14
je     11f6 <init_tracks+0xd6>
lea    0x4(%rbp),%rdi
call   1040 <next_int@plt>
cltq
add    %rax,%rbp
add    $0x8,%rbp
mov    %rbp,%rdi
call   1040 <next_int@plt>
lea    0x1(%rbx),%rcx
cmp    $0x4d54726b,%eax
je     11c0 <init_tracks+0xa0>
xor    %eax,%eax
cmp    %r14,%rbx
setb   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"offset track1 %d\0A\00"
define i32 @init_tracks(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
br label %11
11: ; preds = %20, %3
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = call i32 @next_int(i8* %15)
%17 = icmp ne i32 %16, 1297379947
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
br label %11
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 1, i32* %4
br label %69
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 8
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 0
store i8* %29, i8** %31
%32 = load i8**, i8*** %6
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i8*, i8** %8
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %39)
store i32 1, i32* %9
br label %41
41: ; preds = %65, %27
%42 = load i32, i32* %9
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %68
45: ; preds = %41
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 4
store i8* %47, i8** %5
%48 = load i8*, i8** %5
%49 = call i32 @next_int(i8* %48)
%50 = add nsw i32 4, %49
%51 = load i8*, i8** %5
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds i8, i8* %51, i64 %52
store i8* %53, i8** %5
%54 = load i8*, i8** %5
%55 = call i32 @next_int(i8* %54)
%56 = icmp ne i32 %55, 1297379947
br i1 %56, label %57, label %58
57: ; preds = %45
store i32 1, i32* %4
br label %69
58: ; preds = %45
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 8
%61 = load i8**, i8*** %6
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
store i8* %60, i8** %64
br label %65
65: ; preds = %58
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %41
68: ; preds = %41
store i32 0, i32* %4
br label %69
69: ; preds = %68, %57, %26
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
@.str = [18 x i8] c"offset track1 %d\0A\00"
define i32 @init_tracks(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %46, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %9, %5 ], [ %0, %3 ]
%7 = tail call i32 @next_int(i8* %6)
%8 = icmp eq i32 %7, 1297379947
%9 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %8, label %10, label %5
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 8
store i8* %11, i8** %1
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp sgt i32 %2, 1
br i1 %17, label %18, label %46
18: ; preds = %10
%19 = zext i32 %2 to i64
%20 = zext i32 %2 to i64
%21 = getelementptr inbounds i8, i8* %6, i64 4
%22 = tail call i32 @next_int(i8* %21)
%23 = add nsw i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = tail call i32 @next_int(i8* %25)
%27 = icmp eq i32 %26, 1297379947
br i1 %27, label %36, label %46
28: ; preds = %36
%29 = getelementptr inbounds i8, i8* %37, i64 4
%30 = tail call i32 @next_int(i8* %29)
%31 = add nsw i32 %30, 4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = tail call i32 @next_int(i8* %33)
%35 = icmp eq i32 %34, 1297379947
br i1 %35, label %36, label %43
36: ; preds = %18, %28
%37 = phi i8* [ %33, %28 ], [ %25, %18 ]
%38 = phi i64 [ %41, %28 ], [ 1, %18 ]
%39 = getelementptr inbounds i8, i8* %37, i64 8
%40 = getelementptr inbounds i8*, i8** %1, i64 %38
store i8* %39, i8** %40
%41 = add nuw nsw i64 %38, 1
%42 = icmp eq i64 %41, %20
br i1 %42, label %43, label %28
43: ; preds = %36, %28
%44 = icmp ult i64 %41, %19
%45 = zext i1 %44 to i32
br label %46
46: ; preds = %10, %18, %43, %3
%47 = phi i32 [ 1, %3 ], [ 0, %10 ], [ 1, %18 ], [ %45, %43 ]
ret i32 %47
}