#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 atoi(char *);
int /*<<< orphan*/ displayMem_to_PCM(int /*<<< orphan*/ *, char *, int, int,
                                     int);
int /*<<< orphan*/ error();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt(int, char **, char *);
char *optarg;
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ ti83font(char, char *);
int main(int argc, char *argv[]) {
  char *input_string;
  char *outputFile = strdup("out.raw");
  int base_freq = 1200;
  int bandwidth = 1000;
  int input_flag = 0;
  int opt;
  while ((opt = getopt(argc, argv, "i:f:b:o:")) != -1) {
    switch (opt) {
    case 'i':
      input_string = strdup(optarg);
      input_flag = 1;
      break;
    case 'f':
      base_freq = atoi(optarg);
      break;
    case 'b':
      bandwidth = atoi(optarg);
      break;
    case 'o':
      outputFile = strdup(optarg);
      break;
    default:
      error();
    }
  }
  if (!input_flag)
    error();
  FILE *file = fopen(outputFile, "wb");
  for (int i = 0; i < strlen(input_string); i++) {
    char display_mem[5];
    ti83font(input_string[i], display_mem);
    displayMem_to_PCM(file, &display_mem[0], base_freq, bandwidth, 48000);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8b(%rip),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
movl   $0x4b0,-0x24(%rbp)
movl   $0x3e8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     1284 <main+0xf4>
mov    -0x30(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0xd,%eax
ja     1278 <main+0xe8>
mov    -0x50(%rbp),%rax
lea    0xdf6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dde(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    127f <main+0xef>
mov    0x2dbf(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    127f <main+0xef>
mov    0x2da8(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    127f <main+0xef>
mov    0x2d91(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    127f <main+0xef>
mov    $0x0,%al
call   1050 <error@plt>
jmp    11cb <main+0x3b>
cmpl   $0x0,-0x2c(%rbp)
jne    1295 <main+0x105>
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x20(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jge    130a <main+0x17a>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
lea    -0x41(%rbp),%rsi
movsbl %al,%edi
call   10a0 <ti83font@plt>
mov    -0x38(%rbp),%rdi
lea    -0x41(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    $0xbb80,%r8d
call   1070 <displayMem_to_PCM@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12b0 <main+0x120>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe8e(%rip),%rdi
call   10b0 <strdup@plt>
mov    %rax,0x8(%rsp)
movl   $0x3e8,0x4(%rsp)
mov    $0x4b0,%r12d
lea    0xe77(%rip),%r15
lea    0xe30(%rip),%r14
movl   $0x0,(%rsp)
jmp    11ec <main+0x5c>
nopl   0x0(%rax)
cmp    $0xffffffff,%eax
je     1264 <main+0xd4>
xor    %eax,%eax
call   1050 <error@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
lea    -0x62(%rax),%ecx
cmp    $0xd,%ecx
ja     11e0 <main+0x50>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x2de7(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    11ec <main+0x5c>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
jmp    11ec <main+0x5c>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strdup@plt>
mov    %rax,%r13
movl   $0x1,(%rsp)
jmp    11ec <main+0x5c>
mov    0x2da3(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strdup@plt>
mov    %rax,0x8(%rsp)
jmp    11ec <main+0x5c>
cmpl   $0x0,(%rsp)
jne    1271 <main+0xe1>
xor    %eax,%eax
call   1050 <error@plt>
lea    0xdd1(%rip),%rsi
mov    0x8(%rsp),%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
mov    0x4(%rsp),%r15d
jle    12d8 <main+0x148>
xor    %ebx,%ebx
lea    0x13(%rsp),%rbp
nopl   (%rax)
movsbl 0x0(%r13,%rbx,1),%edi
mov    %rbp,%rsi
call   10a0 <ti83font@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    $0xbb80,%r8d
call   1070 <displayMem_to_PCM@plt>
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     12a0 <main+0x110>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"out.raw\00"
@.str.1 = [9 x i8] c"i:f:b:o:\00"
@optarg = global i8* null
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
store i32 1200, i32* %8
store i32 1000, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %37, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %11
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %38
21: ; preds = %16
%22 = load i32, i32* %11
switch i32 %22, label %35 [
i32 105, label %23
i32 102, label %26
i32 98, label %29
i32 111, label %32
]
23: ; preds = %21
%24 = load i8*, i8** @optarg
%25 = call i8* @strdup(i8* %24)
store i8* %25, i8** %6
store i32 1, i32* %10
br label %37
26: ; preds = %21
%27 = load i8*, i8** @optarg
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
br label %37
29: ; preds = %21
%30 = load i8*, i8** @optarg
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %9
br label %37
32: ; preds = %21
%33 = load i8*, i8** @optarg
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %7
br label %37
35: ; preds = %21
%36 = call i32 (...) @error()
br label %37
37: ; preds = %35, %32, %29, %26, %23
br label %16
38: ; preds = %16
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 (...) @error()
br label %43
43: ; preds = %41, %38
%44 = load i8*, i8** %7
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %12
store i32 0, i32* %13
br label %46
46: ; preds = %64, %43
%47 = load i32, i32* %13
%48 = load i8*, i8** %6
%49 = call i32 @strlen(i8* %48)
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %67
51: ; preds = %46
%52 = load i8*, i8** %6
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%58 = call i32 @ti83font(i8 signext %56, i8* %57)
%59 = load i32*, i32** %12
%60 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = call i32 @displayMem_to_PCM(i32* %59, i8* %60, i32 %61, i32 %62, i32 48000)
br label %64
64: ; preds = %51
%65 = load i32, i32* %13
%66 = add nsw i32 %65, 1
store i32 %66, i32* %13
br label %46
67: ; preds = %46
%68 = load i32*, i32** %12
%69 = call i32 @fclose(i32* %68)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"out.raw\00"
@.str.1 = [9 x i8] c"i:f:b:o:\00"
@optarg = global i8* null
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [5 x i8]
%4 = tail call dereferenceable_or_null(8) i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %27, %2
%6 = phi i32 [ %29, %27 ], [ 1200, %2 ]
%7 = phi i32 [ %12, %27 ], [ 1000, %2 ]
%8 = phi i32 [ %17, %27 ], [ 0, %2 ]
%9 = phi i8* [ %21, %27 ], [ %4, %2 ]
%10 = phi i8* [ %19, %27 ], [ undef, %2 ]
br label %11
11: ; preds = %5, %30
%12 = phi i32 [ %7, %5 ], [ %32, %30 ]
%13 = phi i32 [ %8, %5 ], [ %17, %30 ]
%14 = phi i8* [ %9, %5 ], [ %21, %30 ]
%15 = phi i8* [ %10, %5 ], [ %19, %30 ]
br label %16
16: ; preds = %11, %24
%17 = phi i32 [ %13, %11 ], [ 1, %24 ]
%18 = phi i8* [ %14, %11 ], [ %21, %24 ]
%19 = phi i8* [ %15, %11 ], [ %26, %24 ]
br label %20
20: ; preds = %16, %33
%21 = phi i8* [ %18, %16 ], [ %35, %33 ]
br label %22
22: ; preds = %20, %36
%23 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
switch i32 %23, label %36 [
i32 -1, label %38
i32 105, label %24
i32 102, label %27
i32 98, label %30
i32 111, label %33
]
24: ; preds = %22
%25 = load i8*, i8** @optarg
%26 = tail call i8* @strdup(i8* %25)
br label %16
27: ; preds = %22
%28 = load i8*, i8** @optarg
%29 = tail call i32 @atoi(i8* %28)
br label %5
30: ; preds = %22
%31 = load i8*, i8** @optarg
%32 = tail call i32 @atoi(i8* %31)
br label %11
33: ; preds = %22
%34 = load i8*, i8** @optarg
%35 = tail call i8* @strdup(i8* %34)
br label %20
36: ; preds = %22
%37 = tail call i32 (...) @error()
br label %22
38: ; preds = %22
%39 = icmp eq i32 %17, 0
br i1 %39, label %40, label %42
40: ; preds = %38
%41 = tail call i32 (...) @error()
br label %42
42: ; preds = %40, %38
%43 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @strlen(i8* %19)
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
br label %50
48: ; preds = %50, %42
%49 = call i32 @fclose(i32* %43)
ret i32 0
50: ; preds = %46, %50
%51 = phi i64 [ 0, %46 ], [ %56, %50 ]
%52 = getelementptr inbounds i8, i8* %19, i64 %51
%53 = load i8, i8* %52
%54 = call i32 @ti83font(i8 signext %53, i8* %47)
%55 = call i32 @displayMem_to_PCM(i32* %43, i8* %47, i32 %6, i32 %12, i32 48000)
%56 = add nuw nsw i64 %51, 1
%57 = call i32 @strlen(i8* %19)
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %56, %58
br i1 %59, label %50, label %48
}