#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, unsigned int, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void write(unsigned char *_src, int _size, char *_prefix) {
  FILE *fh;
  unsigned int offset;
  unsigned short songno;
  int size, remain;
  char name[0x20];
  int count = 0;
  songno = 0;
  offset = 0;
  remain = _size;
  do {
    if (_src[offset] != 0x20 && _src[offset + 1] != 0x00) {
      break;
    }
    size = 512;
    remain -= 512;
    while (remain > 0) {
      if ((_src[offset + size + 1] == 0x00 && _src[offset + size] == 0x20)) {
        break;
      }
      remain -= 512;
      size += 512;
      continue;
    }
    sprintf(name, "%s%02d.BIN", _prefix, count);
    printf("%s ofs:0x%04x size:0x%04x no:%02d\n", name, offset, size, count);
    fh = fopen(name, "wb");
    fseek(fh, SEEK_SET, 0);
    fwrite(_src + offset, 1, size, fh);
    fclose(fh);
    offset += size;
    count++;
  } while (offset < _size);
}


x86 assembly (clang, -O0):
<write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x54(%rbp)
movw   $0x0,-0x26(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11bf <write+0x5f>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11bf <write+0x5f>
jmp    12cb <write+0x16b>
movl   $0x200,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
sub    $0x200,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    1230 <write+0xd0>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1215 <write+0xb5>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1215 <write+0xb5>
jmp    1230 <write+0xd0>
mov    -0x30(%rbp),%eax
sub    $0x200,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d1 <write+0x71>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x54(%rbp),%ecx
lea    0xdbe(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x54(%rbp),%r8d
lea    0xdaf(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    %rax,%rdi
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jb     118d <write+0x2d>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,0x10(%rsp)
mov    %rdi,%rbx
xor    %r14d,%r14d
mov    %esi,0xc(%rsp)
mov    %esi,%r12d
xor    %r15d,%r15d
jmp    1228 <write+0xc8>
nopl   0x0(%rax,%rax,1)
add    $0xfffffe00,%r12d
mov    $0x200,%r13d
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
lea    0xe54(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %r15d,%ecx
call   1070 <sprintf@plt>
lea    0xe4b(%rip),%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
call   1040 <printf@plt>
mov    %rbp,%rdi
lea    0xe53(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    0x18(%rsp),%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1080 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    %r14d,%r13d
add    $0x1,%r15d
mov    %r13d,%r14d
cmp    0xc(%rsp),%r13d
jae    12bb <write+0x15b>
mov    %r14d,%eax
cmpb   $0x20,(%rbx,%rax,1)
je     123e <write+0xde>
mov    %rax,%rcx
or     $0x1,%rcx
cmpb   $0x0,(%rbx,%rcx,1)
jne    12bb <write+0x15b>
lea    (%rbx,%rax,1),%rdi
cmp    $0x201,%r12d
mov    %rdi,0x18(%rsp)
jl     1190 <write+0x30>
lea    0x1ff(%r12),%eax
and    $0xfffffe00,%eax
mov    $0x200,%r13d
xor    %ecx,%ecx
jmp    128f <write+0x12f>
nopl   0x0(%rax,%rax,1)
add    $0x200,%r13d
lea    (%r12,%rcx,1),%edx
add    $0xfffffe00,%edx
add    $0xfffffe00,%ecx
cmp    $0x200,%edx
jle    12b0 <write+0x150>
lea    (%r14,%r13,1),%edx
mov    %rdx,%rsi
or     $0x1,%rsi
cmpb   $0x0,(%rbx,%rsi,1)
jne    1270 <write+0x110>
mov    %edx,%edx
cmpb   $0x20,(%rbx,%rdx,1)
jne    1270 <write+0x110>
sub    %r13d,%r12d
jmp    119d <write+0x3d>
sub    %r13d,%r12d
mov    %eax,%r13d
jmp    119d <write+0x3d>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s%02d.BIN\00"
@.str.1 = [35 x i8] c"%s ofs:0x%04x size:0x%04x no:%02d\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
define void @write(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca [32 x i8]
%13 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %13
store i16 0, i16* %9
store i32 0, i32* %8
%14 = load i32, i32* %5
store i32 %14, i32* %11
br label %15
15: ; preds = %95, %3
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp ne i32 %21, 32
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = load i32, i32* %8
%26 = add i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
br label %99
33: ; preds = %23, %15
store i32 512, i32* %10
%34 = load i32, i32* %11
%35 = sub nsw i32 %34, 512
store i32 %35, i32* %11
br label %36
36: ; preds = %61, %33
%37 = load i32, i32* %11
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %66
39: ; preds = %36
%40 = load i8*, i8** %4
%41 = load i32, i32* %8
%42 = load i32, i32* %10
%43 = add i32 %41, %42
%44 = add i32 %43, 1
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %40, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %39
%51 = load i8*, i8** %4
%52 = load i32, i32* %8
%53 = load i32, i32* %10
%54 = add i32 %52, %53
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %51, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp eq i32 %58, 32
br i1 %59, label %60, label %61
60: ; preds = %50
br label %66
61: ; preds = %50, %39
%62 = load i32, i32* %11
%63 = sub nsw i32 %62, 512
store i32 %63, i32* %11
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 512
store i32 %65, i32* %10
br label %36
66: ; preds = %60, %36
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%68 = load i8*, i8** %6
%69 = load i32, i32* %13
%70 = call i32 @sprintf(i8* %67, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %68, i32 %69)
%71 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%72 = load i32, i32* %8
%73 = load i32, i32* %10
%74 = load i32, i32* %13
%75 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %71, i32 %72, i32 %73, i32 %74)
%76 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%77 = call i32* @fopen(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %77, i32** %7
%78 = load i32*, i32** %7
%79 = load i32, i32* @SEEK_SET
%80 = call i32 @fseek(i32* %78, i32 %79, i32 0)
%81 = load i8*, i8** %4
%82 = load i32, i32* %8
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i32, i32* %10
%86 = load i32*, i32** %7
%87 = call i32 @fwrite(i8* %84, i32 1, i32 %85, i32* %86)
%88 = load i32*, i32** %7
%89 = call i32 @fclose(i32* %88)
%90 = load i32, i32* %10
%91 = load i32, i32* %8
%92 = add i32 %91, %90
store i32 %92, i32* %8
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %95
95: ; preds = %66
%96 = load i32, i32* %8
%97 = load i32, i32* %5
%98 = icmp ult i32 %96, %97
br i1 %98, label %15, label %99
99: ; preds = %95, %32
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s%02d.BIN\00"
@.str.1 = [35 x i8] c"%s ofs:0x%04x size:0x%04x no:%02d\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
define void @write(i8* nocapture %0, i32 %1, i8* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
br label %6
6: ; preds = %47, %3
%7 = phi i32 [ 0, %3 ], [ %57, %47 ]
%8 = phi i32 [ %1, %3 ], [ %49, %47 ]
%9 = phi i32 [ 0, %3 ], [ %58, %47 ]
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 32
br i1 %13, label %20, label %14
14: ; preds = %6
%15 = or i32 %7, 1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %60
20: ; preds = %14, %6
%21 = add nsw i32 %8, -512
%22 = icmp sgt i32 %8, 512
br i1 %22, label %23, label %47
23: ; preds = %20
%24 = add nuw i32 %8, 511
%25 = and i32 %24, -512
br label %26
26: ; preds = %23, %41
%27 = phi i64 [ 512, %23 ], [ %42, %41 ]
%28 = phi i32 [ %21, %23 ], [ %43, %41 ]
%29 = trunc i64 %27 to i32
%30 = add i32 %7, %29
%31 = or i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %26
%37 = zext i32 %30 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 32
br i1 %40, label %45, label %41
41: ; preds = %36, %26
%42 = add nuw nsw i64 %27, 512
%43 = add nsw i32 %28, -512
%44 = icmp sgt i32 %28, 512
br i1 %44, label %26, label %47
45: ; preds = %36
%46 = trunc i64 %27 to i32
br label %47
47: ; preds = %41, %45, %20
%48 = phi i32 [ 512, %20 ], [ %46, %45 ], [ %25, %41 ]
%49 = phi i32 [ %21, %20 ], [ %28, %45 ], [ %43, %41 ]
%50 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %9)
%51 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %7, i32 %48, i32 %9)
%52 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @fseek(i32* %52, i32 %53, i32 0)
%55 = call i32 @fwrite(i8* %11, i32 1, i32 %48, i32* %52)
%56 = call i32 @fclose(i32* %52)
%57 = add i32 %48, %7
%58 = add nuw nsw i32 %9, 1
%59 = icmp ult i32 %57, %1
br i1 %59, label %6, label %60
60: ; preds = %14, %47
ret void
}