#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*/ free(char *);
char *malloc(int);
size_t strlen(char *);
int /*<<< orphan*/ wav_close(int /*<<< orphan*/ **);
int /*<<< orphan*/ wav_note(int /*<<< orphan*/ **, double, double);
int /*<<< orphan*/ wav_open(int /*<<< orphan*/ **, char *);
void morse2wav(char *filename, char *morse) {
  int counter = 0, i = 0, l = 0;
  size_t length = 0;
  char chr;
  char *clean_morse = NULL;
  FILE *wav = NULL;
  length = strlen(morse);
  clean_morse = malloc(sizeof(char) * length + 1);
  for (i = 0, l = (int)length; i < l; i++) {
    chr = morse[i];
    if (chr == '.' || chr == '-' || chr == ' ' || chr == '/') {
      clean_morse[counter++] = chr;
    }
  }
  clean_morse[counter] = '\0';
  length = strlen(clean_morse);
  wav_open(&wav, filename);
  for (i = 0, l = (int)length; i < l; i++) {
    switch (clean_morse[i]) {
    case '.':
      wav_note(&wav, 0.25, 1000.0);
      wav_note(&wav, 0.25, 0.0);
      break;
    case '-':
      wav_note(&wav, 0.25 * 3, 1000.0);
      wav_note(&wav, 0.25, 0.0);
      break;
    case '/':
      wav_note(&wav, 0.25, 0.0);
      break;
    case ' ':
    default:
      wav_note(&wav, 0.25 * 3, 0.0);
      break;
    }
  }
  wav_close(&wav);
  if (clean_morse) {
    free(clean_morse);
  }
}


x86 assembly (clang, -O0):
<morse2wav>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1248 <morse2wav+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x2e,%eax
je     121d <morse2wav+0xbd>
movsbl -0x29(%rbp),%eax
cmp    $0x2d,%eax
je     121d <morse2wav+0xbd>
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
je     121d <morse2wav+0xbd>
movsbl -0x29(%rbp),%eax
cmp    $0x2f,%eax
jne    1235 <morse2wav+0xd5>
mov    -0x29(%rbp),%dl
mov    -0x38(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123a <morse2wav+0xda>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cf <morse2wav+0x6f>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   1080 <wav_open@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1363 <morse2wav+0x203>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffe0,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0xf,%eax
ja     133c <morse2wav+0x1dc>
mov    -0x48(%rbp),%rax
lea    0xd67(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x40(%rbp),%rdi
movsd  0xd3a(%rip),%xmm0
movsd  0xd42(%rip),%xmm1
call   1070 <wav_note@plt>
lea    -0x40(%rbp),%rdi
movsd  0xd21(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1070 <wav_note@plt>
jmp    1350 <morse2wav+0x1f0>
lea    -0x40(%rbp),%rdi
movsd  0xd10(%rip),%xmm0
movsd  0xd10(%rip),%xmm1
call   1070 <wav_note@plt>
lea    -0x40(%rbp),%rdi
movsd  0xcef(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1070 <wav_note@plt>
jmp    1350 <morse2wav+0x1f0>
lea    -0x40(%rbp),%rdi
movsd  0xcd6(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1070 <wav_note@plt>
jmp    1350 <morse2wav+0x1f0>
jmp    133c <morse2wav+0x1dc>
lea    -0x40(%rbp),%rdi
movsd  0xcc0(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1070 <wav_note@plt>
jmp    1355 <morse2wav+0x1f5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127c <morse2wav+0x11c>
lea    -0x40(%rbp),%rdi
call   1040 <wav_close@plt>
cmpq   $0x0,-0x38(%rbp)
je     1380 <morse2wav+0x220>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morse2wav>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    11d9 <morse2wav+0x79>
mov    %r12d,%edx
and    $0x1,%r12d
cmp    $0x1,%rdx
jne    129d <morse2wav+0x13d>
xor    %ecx,%ecx
xor    %eax,%eax
test   %r12,%r12
je     11db <morse2wav+0x7b>
movzbl (%r15,%rcx,1),%ecx
cmp    $0x2f,%rcx
ja     11db <morse2wav+0x7b>
movabs $0xe00100000000,%rdx
bt     %rcx,%rdx
jae    11db <morse2wav+0x7b>
movslq %eax,%rdx
add    $0x1,%eax
mov    %cl,0x0(%r13,%rdx,1)
jmp    11db <morse2wav+0x7b>
xor    %eax,%eax
cltq
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1080 <wav_open@plt>
test   %ebx,%ebx
jle    127d <morse2wav+0x11d>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
jmp    1244 <morse2wav+0xe4>
nop
mov    %r14,%rdi
movsd  0xde5(%rip),%xmm0
movsd  0xded(%rip),%xmm1
call   1070 <wav_note@plt>
movsd  0xdd0(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %r14,%rdi
call   1070 <wav_note@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     127d <morse2wav+0x11d>
movsbl 0x0(%r13,%rbx,1),%eax
cmp    $0x2d,%eax
je     1270 <morse2wav+0x110>
movsd  0xda9(%rip),%xmm0
cmp    $0x2f,%eax
je     1230 <morse2wav+0xd0>
cmp    $0x2e,%eax
je     1210 <morse2wav+0xb0>
movsd  0xd9f(%rip),%xmm0
jmp    1230 <morse2wav+0xd0>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
movsd  0xd8d(%rip),%xmm0
jmp    121b <morse2wav+0xbb>
lea    0x8(%rsp),%rdi
call   1040 <wav_close@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
sub    %r12,%rdx
xor    %ecx,%ecx
movabs $0xe00100000000,%rsi
xor    %eax,%eax
jmp    12bd <morse2wav+0x15d>
add    $0x2,%rcx
cmp    %rcx,%rdx
je     11ac <morse2wav+0x4c>
movzbl (%r15,%rcx,1),%edi
cmp    $0x2f,%rdi
ja     12d9 <morse2wav+0x179>
bt     %rdi,%rsi
jae    12d9 <morse2wav+0x179>
movslq %eax,%rbx
add    $0x1,%eax
mov    %dil,0x0(%r13,%rbx,1)
movzbl 0x1(%r15,%rcx,1),%edi
cmp    $0x2f,%rdi
ja     12b0 <morse2wav+0x150>
bt     %rdi,%rsi
jae    12b0 <morse2wav+0x150>
movslq %eax,%rbx
add    $0x1,%eax
mov    %dil,0x0(%r13,%rbx,1)
jmp    12b0 <morse2wav+0x150>

LLVM IR (-O0):
define void @morse2wav(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i64 0, i64* %8
store i8* null, i8** %10
store i32* null, i32** %11
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = mul i64 1, %14
%16 = add i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %10
store i32 0, i32* %6
%19 = load i64, i64* %8
%20 = trunc i64 %19 to i32
store i32 %20, i32* %7
br label %21
21: ; preds = %54, %2
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %57
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %9
%31 = load i8, i8* %9
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %46, label %34
34: ; preds = %25
%35 = load i8, i8* %9
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 45
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i8, i8* %9
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 32
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i8, i8* %9
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 47
br i1 %45, label %46, label %53
46: ; preds = %42, %38, %34, %25
%47 = load i8, i8* %9
%48 = load i8*, i8** %10
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 %47, i8* %52
br label %53
53: ; preds = %46, %42
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %21
57: ; preds = %21
%58 = load i8*, i8** %10
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
%62 = load i8*, i8** %10
%63 = call i64 @strlen(i8* %62)
store i64 %63, i64* %8
%64 = load i8*, i8** %3
%65 = call i32 @wav_open(i32** %11, i8* %64)
store i32 0, i32* %6
%66 = load i64, i64* %8
%67 = trunc i64 %66 to i32
store i32 %67, i32* %7
br label %68
68: ; preds = %91, %57
%69 = load i32, i32* %6
%70 = load i32, i32* %7
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %94
72: ; preds = %68
%73 = load i8*, i8** %10
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
switch i32 %78, label %88 [
i32 46, label %79
i32 45, label %82
i32 47, label %85
i32 32, label %87
]
79: ; preds = %72
%80 = call i32 @wav_note(i32** %11, double 2.500000e-01, double 1.000000e+03)
%81 = call i32 @wav_note(i32** %11, double 2.500000e-01, double 0.000000e+00)
br label %90
82: ; preds = %72
%83 = call i32 @wav_note(i32** %11, double 7.500000e-01, double 1.000000e+03)
%84 = call i32 @wav_note(i32** %11, double 2.500000e-01, double 0.000000e+00)
br label %90
85: ; preds = %72
%86 = call i32 @wav_note(i32** %11, double 2.500000e-01, double 0.000000e+00)
br label %90
87: ; preds = %72
br label %88
88: ; preds = %72, %87
%89 = call i32 @wav_note(i32** %11, double 7.500000e-01, double 0.000000e+00)
br label %90
90: ; preds = %88, %85, %82, %79
br label %91
91: ; preds = %90
%92 = load i32, i32* %6
%93 = add nsw i32 %92, 1
store i32 %93, i32* %6
br label %68
94: ; preds = %68
%95 = call i32 @wav_close(i32** %11)
%96 = load i8*, i8** %10
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = load i8*, i8** %10
%100 = call i32 @free(i8* %99)
br label %101
101: ; preds = %98, %94
ret void
}

LLVM IR (-O2):
define void @morse2wav(i8* %0, i8* nocapture %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %52
10: ; preds = %2
%11 = and i64 %5, 4294967295
%12 = and i64 %5, 1
%13 = icmp eq i64 %11, 1
br i1 %13, label %40, label %14
14: ; preds = %10
%15 = sub nsw i64 %11, %12
br label %16
16: ; preds = %35, %14
%17 = phi i64 [ 0, %14 ], [ %37, %35 ]
%18 = phi i32 [ 0, %14 ], [ %36, %35 ]
%19 = phi i64 [ 0, %14 ], [ %38, %35 ]
%20 = getelementptr inbounds i8, i8* %1, i64 %17
%21 = load i8, i8* %20
switch i8 %21, label %26 [
i8 47, label %22
i8 46, label %22
i8 45, label %22
i8 32, label %22
]
22: ; preds = %16, %16, %16, %16
%23 = add nsw i32 %18, 1
%24 = sext i32 %18 to i64
%25 = getelementptr inbounds i8, i8* %8, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %16, %22
%27 = phi i32 [ %23, %22 ], [ %18, %16 ]
%28 = or i64 %17, 1
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = load i8, i8* %29
switch i8 %30, label %35 [
i8 47, label %31
i8 46, label %31
i8 45, label %31
i8 32, label %31
]
31: ; preds = %26, %26, %26, %26
%32 = add nsw i32 %27, 1
%33 = sext i32 %27 to i64
%34 = getelementptr inbounds i8, i8* %8, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %31, %26
%36 = phi i32 [ %32, %31 ], [ %27, %26 ]
%37 = add nuw nsw i64 %17, 2
%38 = add i64 %19, 2
%39 = icmp eq i64 %38, %15
br i1 %39, label %40, label %16
40: ; preds = %35, %10
%41 = phi i32 [ undef, %10 ], [ %36, %35 ]
%42 = phi i64 [ 0, %10 ], [ %37, %35 ]
%43 = phi i32 [ 0, %10 ], [ %36, %35 ]
%44 = icmp eq i64 %12, 0
br i1 %44, label %52, label %45
45: ; preds = %40
%46 = getelementptr inbounds i8, i8* %1, i64 %42
%47 = load i8, i8* %46
switch i8 %47, label %52 [
i8 47, label %48
i8 46, label %48
i8 45, label %48
i8 32, label %48
]
48: ; preds = %45, %45, %45, %45
%49 = add nsw i32 %43, 1
%50 = sext i32 %43 to i64
%51 = getelementptr inbounds i8, i8* %8, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %40, %48, %45, %2
%53 = phi i32 [ 0, %2 ], [ %41, %40 ], [ %49, %48 ], [ %43, %45 ]
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %8, i64 %54
store i8 0, i8* %55
%56 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%57 = call i32 @wav_open(i32** %3, i8* %0)
%58 = trunc i64 %56 to i32
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %77
60: ; preds = %52
%61 = and i64 %56, 4294967295
br label %62
62: ; preds = %60, %72
%63 = phi i64 [ 0, %60 ], [ %75, %72 ]
%64 = getelementptr inbounds i8, i8* %8, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
switch i32 %66, label %71 [
i32 46, label %67
i32 45, label %69
i32 47, label %72
]
67: ; preds = %62
%68 = call i32 @wav_note(i32** %3, double 2.500000e-01, double 1.000000e+03)
br label %72
69: ; preds = %62
%70 = call i32 @wav_note(i32** %3, double 7.500000e-01, double 1.000000e+03)
br label %72
71: ; preds = %62
br label %72
72: ; preds = %62, %67, %69, %71
%73 = phi double [ 2.500000e-01, %67 ], [ 2.500000e-01, %69 ], [ 7.500000e-01, %71 ], [ 2.500000e-01, %62 ]
%74 = call i32 @wav_note(i32** %3, double %73, double 0.000000e+00)
%75 = add nuw nsw i64 %63, 1
%76 = icmp eq i64 %75, %61
br i1 %76, label %77, label %62
77: ; preds = %72, %52
%78 = call i32 @wav_close(i32** %3)
%79 = call i32 @free(i8* %8)
ret void
}