#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ print_chunk(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               unsigned char *, int, int);
void print_song_struct(int channel_count, int unused_channels,
                       int default_tempo, int *order_data_size,
                       unsigned char *order_data, int song_length,
                       const char *label_prefix, FILE *out) {
  int chn;
  int order_offset = 0;
  fprintf(out, "%ssong:\n", label_prefix);
  for (chn = 0; chn < channel_count; ++chn) {
    if (chn >= 5)
      break;
    if (unused_channels & (1 << chn)) {
      fprintf(out, ".db $FF\n");
    } else {
      fprintf(out, ".db %d,%d\n", order_offset, default_tempo);
      order_offset += order_data_size[chn] + 2;
    }
  }
  fprintf(out, ".dw %sinstrument_table\n", label_prefix);
  fprintf(out, ".dw %spattern_table\n", label_prefix);
  order_offset = 0;
  for (chn = 0; chn < channel_count; ++chn) {
    if (chn >= 5)
      break;
    if (unused_channels & (1 << chn))
      continue;
    print_chunk(out, 0, &order_data[chn * song_length], order_data_size[chn],
                16);
    fprintf(out, ".db $FE,%d\n", order_offset);
    order_offset += order_data_size[chn] + 2;
  }
}


x86 assembly (clang, -O0):
<print_song_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f4 <print_song_struct+0xd4>
cmpl   $0x5,-0x28(%rbp)
jl     1184 <print_song_struct+0x64>
jmp    11f4 <print_song_struct+0xd4>
mov    -0x8(%rbp),%eax
mov    -0x28(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11b5 <print_song_struct+0x95>
mov    0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11e1 <print_song_struct+0xc1>
mov    0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0x2,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11e6 <print_song_struct+0xc6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1169 <print_song_struct+0x49>
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12cb <print_song_struct+0x1ab>
cmpl   $0x5,-0x28(%rbp)
jl     1249 <print_song_struct+0x129>
jmp    12cb <print_song_struct+0x1ab>
mov    -0x8(%rbp),%eax
mov    -0x28(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1268 <print_song_struct+0x148>
jmp    12bd <print_song_struct+0x19d>
mov    0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
add    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
xor    %esi,%esi
mov    $0x10,%r8d
call   1030 <print_chunk@plt>
mov    0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0x2,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    122e <print_song_struct+0x10e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_song_struct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r15d
mov    %r8,%rbx
mov    %rcx,0x20(%rsp)
mov    %edx,0x8(%rsp)
mov    %esi,%r12d
mov    %edi,%ebp
mov    0x78(%rsp),%r14
mov    0x70(%rsp),%r13
lea    0xe9d(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
jle    12d6 <print_song_struct+0x1a6>
mov    %r13,0x30(%rsp)
mov    %r15d,0x18(%rsp)
mov    %rbp,0x28(%rsp)
lea    -0x1(%rbp),%eax
cmp    $0x4,%eax
mov    $0x4,%r15d
mov    %eax,0x14(%rsp)
cmovb  %eax,%r15d
add    $0x1,%r15d
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    11de <print_song_struct+0xae>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xe58(%rip),%rsi
mov    %ebp,%edx
mov    0x8(%rsp),%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x20(%rsp),%rax
mov    (%rax,%r13,4),%eax
add    %eax,%ebp
add    $0x2,%ebp
add    $0x1,%r13
cmp    %r13,%r15
je     11ff <print_song_struct+0xcf>
bt     %r13d,%r12d
jae    11b0 <print_song_struct+0x80>
mov    $0x8,%esi
mov    $0x1,%edx
lea    0xe14(%rip),%rdi
mov    %r14,%rcx
call   1050 <fwrite@plt>
jmp    11d5 <print_song_struct+0xa5>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
mov    0x30(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmpl   $0x0,0x28(%rsp)
jle    12c7 <print_song_struct+0x197>
movslq 0x18(%rsp),%rcx
mov    0x14(%rsp),%eax
cmp    $0x4,%eax
mov    $0x4,%edx
cmovb  %eax,%edx
add    $0x1,%edx
xor    %r13d,%r13d
xor    %ebp,%ebp
mov    %rcx,0x8(%rsp)
mov    %r12d,0x1c(%rsp)
mov    0x20(%rsp),%r15
jmp    127c <print_song_struct+0x14c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
add    %rcx,%rbx
cmp    %r13,%rdx
je     12c7 <print_song_struct+0x197>
bt     %r13d,%r12d
jb     1270 <print_song_struct+0x140>
mov    (%r15,%r13,4),%ecx
mov    %r14,%rdi
xor    %esi,%esi
mov    %rdx,%r12
mov    %rbx,%rdx
mov    $0x10,%r8d
call   1030 <print_chunk@plt>
mov    %r14,%rdi
lea    0xda4(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12,%rdx
mov    0x8(%rsp),%rcx
mov    0x1c(%rsp),%r12d
mov    (%r15,%r13,4),%eax
add    %eax,%ebp
add    $0x2,%ebp
jmp    1270 <print_song_struct+0x140>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd40(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xd44(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%ssong:\0A\00"
@.str.1 = [9 x i8] c".db $FF\0A\00"
@.str.2 = [11 x i8] c".db %d,%d\0A\00"
@.str.3 = [24 x i8] c".dw %sinstrument_table\0A\00"
@.str.4 = [21 x i8] c".dw %spattern_table\0A\00"
@.str.5 = [12 x i8] c".db $FE,%d\0A\00"
define void @print_song_struct(i32 %0, i32 %1, i32 %2, i32* %3, i8* %4, i32 %5, i8* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32* %3, i32** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i8* %6, i8** %15
store i32* %7, i32** %16
store i32 0, i32* %18
%19 = load i32*, i32** %16
%20 = load i8*, i8** %15
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 0, i32* %17
br label %22
22: ; preds = %53, %8
%23 = load i32, i32* %17
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %56
26: ; preds = %22
%27 = load i32, i32* %17
%28 = icmp sge i32 %27, 5
br i1 %28, label %29, label %30
29: ; preds = %26
br label %56
30: ; preds = %26
%31 = load i32, i32* %10
%32 = load i32, i32* %17
%33 = shl i32 1, %32
%34 = and i32 %31, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32*, i32** %16
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %52
39: ; preds = %30
%40 = load i32*, i32** %16
%41 = load i32, i32* %18
%42 = load i32, i32* %11
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32*, i32** %12
%45 = load i32, i32* %17
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 2
%50 = load i32, i32* %18
%51 = add nsw i32 %50, %49
store i32 %51, i32* %18
br label %52
52: ; preds = %39, %36
br label %53
53: ; preds = %52
%54 = load i32, i32* %17
%55 = add nsw i32 %54, 1
store i32 %55, i32* %17
br label %22
56: ; preds = %29, %22
%57 = load i32*, i32** %16
%58 = load i8*, i8** %15
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32*, i32** %16
%61 = load i8*, i8** %15
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %61)
store i32 0, i32* %18
store i32 0, i32* %17
br label %63
63: ; preds = %103, %56
%64 = load i32, i32* %17
%65 = load i32, i32* %9
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %106
67: ; preds = %63
%68 = load i32, i32* %17
%69 = icmp sge i32 %68, 5
br i1 %69, label %70, label %71
70: ; preds = %67
br label %106
71: ; preds = %67
%72 = load i32, i32* %10
%73 = load i32, i32* %17
%74 = shl i32 1, %73
%75 = and i32 %72, %74
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %71
br label %103
78: ; preds = %71
%79 = load i32*, i32** %16
%80 = load i8*, i8** %13
%81 = load i32, i32* %17
%82 = load i32, i32* %14
%83 = mul nsw i32 %81, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %80, i64 %84
%86 = load i32*, i32** %12
%87 = load i32, i32* %17
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %86, i64 %88
%90 = load i32, i32* %89
%91 = call i32 @print_chunk(i32* %79, i32 0, i8* %85, i32 %90, i32 16)
%92 = load i32*, i32** %16
%93 = load i32, i32* %18
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %93)
%95 = load i32*, i32** %12
%96 = load i32, i32* %17
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %95, i64 %97
%99 = load i32, i32* %98
%100 = add nsw i32 %99, 2
%101 = load i32, i32* %18
%102 = add nsw i32 %101, %100
store i32 %102, i32* %18
br label %103
103: ; preds = %78, %77
%104 = load i32, i32* %17
%105 = add nsw i32 %104, 1
store i32 %105, i32* %17
br label %63
106: ; preds = %70, %63
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%ssong:\0A\00"
@.str.1 = [9 x i8] c".db $FF\0A\00"
@.str.2 = [11 x i8] c".db %d,%d\0A\00"
@.str.3 = [24 x i8] c".dw %sinstrument_table\0A\00"
@.str.4 = [21 x i8] c".dw %spattern_table\0A\00"
@.str.5 = [12 x i8] c".db $FE,%d\0A\00"
define void @print_song_struct(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i8* %4, i32 %5, i8* %6, i32* %7) {
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%10 = icmp slt i32 %0, 1
br i1 %10, label %65, label %11
11: ; preds = %8
%12 = add nsw i32 %0, -1
%13 = call i32 @llvm.umin.i32(i32 %12, i32 4)
%14 = add nuw nsw i32 %13, 1
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %11, %31
%17 = phi i64 [ 0, %11 ], [ %33, %31 ]
%18 = phi i32 [ 0, %11 ], [ %32, %31 ]
%19 = trunc i64 %17 to i32
%20 = shl nuw nsw i32 1, %19
%21 = and i32 %20, %1
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 8, i64 1, i32* %7)
br label %31
25: ; preds = %16
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %2)
%27 = getelementptr inbounds i32, i32* %3, i64 %17
%28 = load i32, i32* %27
%29 = add i32 %18, 2
%30 = add i32 %29, %28
br label %31
31: ; preds = %23, %25
%32 = phi i32 [ %18, %23 ], [ %30, %25 ]
%33 = add nuw nsw i64 %17, 1
%34 = icmp eq i64 %33, %15
br i1 %34, label %35, label %16
35: ; preds = %31
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br i1 %10, label %68, label %38
38: ; preds = %35
%39 = sext i32 %5 to i64
%40 = add nsw i32 %0, -1
%41 = call i32 @llvm.umin.i32(i32 %40, i32 4)
%42 = add nuw nsw i32 %41, 1
%43 = zext i32 %42 to i64
br label %44
44: ; preds = %38, %61
%45 = phi i64 [ 0, %38 ], [ %63, %61 ]
%46 = phi i32 [ 0, %38 ], [ %62, %61 ]
%47 = trunc i64 %45 to i32
%48 = shl nuw nsw i32 1, %47
%49 = and i32 %48, %1
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %44
%52 = mul nsw i64 %45, %39
%53 = getelementptr inbounds i8, i8* %4, i64 %52
%54 = getelementptr inbounds i32, i32* %3, i64 %45
%55 = load i32, i32* %54
%56 = tail call i32 @print_chunk(i32* %7, i32 0, i8* %53, i32 %55, i32 16)
%57 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%58 = load i32, i32* %54
%59 = add i32 %46, 2
%60 = add i32 %59, %58
br label %61
61: ; preds = %44, %51
%62 = phi i32 [ %46, %44 ], [ %60, %51 ]
%63 = add nuw nsw i64 %45, 1
%64 = icmp eq i64 %63, %43
br i1 %64, label %68, label %44
65: ; preds = %8
%66 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%67 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %68
68: ; preds = %61, %65, %35
ret void
}