#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int main(int argc, char **argv) {
  FILE *fp = fopen("bgaregga_0-test.vgm", "a");
  char i = (char)(0x80 & 0xFF);
  while (i != 0) {
    printf("Writing OKIM6295 Sample 0x%X Playback...\n", (i - 0x80) & 0xFF);
    fputc(0x61, fp);
    fputc(0xFF, fp);
    fputc(0xFF, fp);
    fputc(0xB8, fp);
    fputc(0x00, fp);
    fputc(0x78, fp);
    fputc(0xB8, fp);
    fputc(0x00, fp);
    fputc(i & 0xFF, fp);
    fputc(0xB8, fp);
    fputc(0x00, fp);
    fputc(0x10, fp);
    i++;
  }
  fputc(0x66, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x80,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
je     124c <main+0x10c>
movsbl -0x19(%rbp),%eax
sub    $0x80,%eax
and    $0xff,%eax
lea    0xe83(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    $0x61,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xff,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xff,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xb8,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x78,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xb8,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
movsbl -0x19(%rbp),%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xb8,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x10,%edi
call   1050 <fputc@plt>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1171 <main+0x31>
mov    -0x18(%rbp),%rsi
mov    $0x66,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xeb0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
lea    0x80(%rbp),%r15d
movsbl %bpl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x61,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xff,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xff,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xb8,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x78,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xb8,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xb8,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
cmp    $0x80,%ebp
jne    1170 <main+0x30>
mov    $0x66,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"bgaregga_0-test.vgm\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [42 x i8] c"Writing OKIM6295 Sample 0x%X Playback...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
store i8 -128, i8* %7
br label %9
9: ; preds = %13, %2
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 128
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8 signext %18)
%20 = load i32*, i32** %6
%21 = call i32 @fputc(i32 97, i32* %20)
%22 = load i32*, i32** %6
%23 = call i32 @fputc(i32 255, i32* %22)
%24 = load i32*, i32** %6
%25 = call i32 @fputc(i32 255, i32* %24)
%26 = load i32*, i32** %6
%27 = call i32 @fputc(i32 184, i32* %26)
%28 = load i32*, i32** %6
%29 = call i32 @fputc(i32 0, i32* %28)
%30 = load i32*, i32** %6
%31 = call i32 @fputc(i32 120, i32* %30)
%32 = load i32*, i32** %6
%33 = call i32 @fputc(i32 184, i32* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fputc(i32 0, i32* %34)
%36 = load i8, i8* %7
%37 = sext i8 %36 to i32
%38 = and i32 %37, 255
%39 = load i32*, i32** %6
%40 = call i32 @fputc(i32 %38, i32* %39)
%41 = load i32*, i32** %6
%42 = call i32 @fputc(i32 184, i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fputc(i32 0, i32* %43)
%45 = load i32*, i32** %6
%46 = call i32 @fputc(i32 16, i32* %45)
%47 = load i8, i8* %7
%48 = add i8 %47, 1
store i8 %48, i8* %7
br label %9
49: ; preds = %9
%50 = load i32*, i32** %6
%51 = call i32 @fputc(i32 102, i32* %50)
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"bgaregga_0-test.vgm\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [42 x i8] c"Writing OKIM6295 Sample 0x%X Playback...\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %2, %4
%5 = phi i32 [ 128, %2 ], [ %21, %4 ]
%6 = trunc i32 %5 to i8
%7 = xor i8 %6, -128
%8 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8 signext %7)
%9 = tail call i32 @fputc(i32 97, i32* %3)
%10 = tail call i32 @fputc(i32 255, i32* %3)
%11 = tail call i32 @fputc(i32 255, i32* %3)
%12 = tail call i32 @fputc(i32 184, i32* %3)
%13 = tail call i32 @fputc(i32 0, i32* %3)
%14 = tail call i32 @fputc(i32 120, i32* %3)
%15 = tail call i32 @fputc(i32 184, i32* %3)
%16 = tail call i32 @fputc(i32 0, i32* %3)
%17 = tail call i32 @fputc(i32 %5, i32* %3)
%18 = tail call i32 @fputc(i32 184, i32* %3)
%19 = tail call i32 @fputc(i32 0, i32* %3)
%20 = tail call i32 @fputc(i32 16, i32* %3)
%21 = add nuw nsw i32 %5, 1
%22 = icmp eq i32 %21, 256
br i1 %22, label %23, label %4
23: ; preds = %4
%24 = tail call i32 @fputc(i32 102, i32* %3)
%25 = tail call i32 @fclose(i32* %3)
ret i32 0
}