#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*/ err(int, char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ play_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
void pcspkr_play(const char *infilename, const char *outfilename) {
  FILE *infp, *outfp;
  infp = outfp = NULL;
  if ((infp = fopen(infilename, "r")) == NULL)
    err(2, "\"%s\"", infilename);
  if (outfilename) {
    if ((outfp = fopen(outfilename, "wb")) == NULL)
      err(2, "\"%s\"", outfilename);
  }
  play_file(infp, outfp);
  fclose(infp);
  if (outfp)
    fclose(outfp);
}


x86 assembly (clang, -O0):
<pcspkr_play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1193 <pcspkr_play+0x53>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xe74(%rip),%rsi
call   1050 <err@plt>
cmpq   $0x0,-0x10(%rbp)
je     11d6 <pcspkr_play+0x96>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d1 <pcspkr_play+0x91>
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe36(%rip),%rsi
call   1050 <err@plt>
jmp    11d6 <pcspkr_play+0x96>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <play_file@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1200 <pcspkr_play+0xc0>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcspkr_play>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1166 <pcspkr_play+0x26>
test   %r14,%r14
jne    117f <pcspkr_play+0x3f>
jmp    11aa <pcspkr_play+0x6a>
lea    0xe95(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1050 <err@plt>
test   %r14,%r14
je     11aa <pcspkr_play+0x6a>
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ac <pcspkr_play+0x6c>
lea    0xe65(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
call   1050 <err@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <play_file@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %rbx,%rbx
je     11d1 <pcspkr_play+0x91>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\22%s\22\00"
@.str.2 = [3 x i8] c"wb\00"
define void @pcspkr_play(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %6
store i32* null, i32** %5
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = call i32 @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
br label %24
24: ; preds = %23, %13
%25 = load i32*, i32** %5
%26 = load i32*, i32** %6
%27 = call i32 @play_file(i32* %25, i32* %26)
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %24
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\22%s\22\00"
@.str.2 = [3 x i8] c"wb\00"
define void @pcspkr_play(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %2
%8 = icmp eq i8* %1, null
br i1 %8, label %14, label %9
9: ; preds = %7
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %9, %12, %7
%15 = phi i32* [ null, %12 ], [ %10, %9 ], [ null, %7 ]
%16 = tail call i32 @play_file(i32* %3, i32* %15)
%17 = tail call i32 @fclose(i32* %3)
%18 = icmp eq i32* %15, null
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @fclose(i32* %15)
br label %21
21: ; preds = %19, %14
ret void
}