#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 */
scalar_t__ imd_parse_track(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int imd_unpack(unsigned char *diskbuff, unsigned char *imgbuff) {
  int ptr, i;
  unsigned char track[128 * 26];
  for (ptr = 0; diskbuff[ptr] != 0x1a; ptr++)
    ;
  ptr++;
  for (i = 0; i < 77 * 2; i++) {
    ptr += imd_parse_track(diskbuff, ptr, track);
    memcpy(imgbuff + (3328 * i), track, 3328);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<imd_unpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x1a,%eax
je     1162 <imd_unpack+0x42>
jmp    1154 <imd_unpack+0x34>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <imd_unpack+0x1a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x9a,-0x18(%rbp)
jge    11ce <imd_unpack+0xae>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0xd20(%rbp),%rdx
call   1040 <imd_parse_track@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0xd00,-0x18(%rbp),%eax
cltq
add    %rax,%rdi
lea    -0xd20(%rbp),%rsi
mov    $0xd00,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1172 <imd_unpack+0x52>
mov    -0x14(%rbp),%eax
add    $0xd20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imd_unpack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd08,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
cmpb   $0x1a,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1140 <imd_unpack+0x20>
xor    %ebp,%ebp
mov    %rsp,%r12
mov    %ebx,%r13d
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1040 <imd_parse_track@plt>
mov    %rax,%rbx
add    %r13d,%ebx
lea    (%r14,%rbp,1),%rdi
mov    %r12,%rsi
mov    $0xd00,%edx
call   1030 <memcpy@plt>
add    $0xd00,%rbp
cmp    $0x7d200,%rbp
jne    1150 <imd_unpack+0x30>
mov    %ebx,%eax
add    $0xd08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @imd_unpack(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3328 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %8
8: ; preds = %17, %2
%9 = load i8*, i8** %3
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 26
br i1 %15, label %16, label %20
16: ; preds = %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %8
20: ; preds = %8
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
store i32 0, i32* %6
br label %23
23: ; preds = %42, %20
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 154
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = getelementptr inbounds [3328 x i8], [3328 x i8]* %7, i64 0, i64 0
%30 = call i64 @imd_parse_track(i8* %27, i32 %28, i8* %29)
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %5
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = mul nsw i32 3328, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = getelementptr inbounds [3328 x i8], [3328 x i8]* %7, i64 0, i64 0
%41 = call i32 @memcpy(i8* %39, i8* %40, i32 3328)
br label %42
42: ; preds = %26
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %23
45: ; preds = %23
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @imd_unpack(i8* %0, i8* %1) {
%3 = alloca [3328 x i8]
%4 = getelementptr inbounds [3328 x i8], [3328 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ %10, %5 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 26
%10 = add nuw i64 %6, 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = trunc i64 %6 to i32
%13 = add nuw nsw i32 %12, 1
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %23, %14 ]
%16 = phi i32 [ %13, %11 ], [ %19, %14 ]
%17 = call i64 @imd_parse_track(i8* %0, i32 %16, i8* %4)
%18 = trunc i64 %17 to i32
%19 = add i32 %16, %18
%20 = mul nuw nsw i64 %15, 3328
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = call i32 @memcpy(i8* %21, i8* %4, i32 3328)
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, 154
br i1 %24, label %25, label %14
25: ; preds = %14
ret i32 %19
}