#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 */

/* Variables and functions */
char *malloc(int);
char *stringcutter(char *, int, char, char, int *);
int strlen(char *);
char tablelookup(char *);
char *morse2text(char *data, int size, char letterindent, char wordindent) {
  int sizeleft = size;
  int status = 1;
  int textbuffercounter = 0;
  char letterbuffer = 0;
  char *codebuffer = malloc(sizeof(char) * 1024);
  char *textbuffer = malloc(sizeof(char) * 1024);
  while (1) {
    codebuffer =
        stringcutter(data, sizeleft, letterindent, wordindent, &status);
    sizeleft = sizeleft - strlen(codebuffer) - 1;
    data = data + strlen(codebuffer) + 1;
    letterbuffer = tablelookup(codebuffer);
    textbuffer[textbuffercounter] = letterbuffer;
    textbuffercounter++;
    if (status == 0) {
      textbuffer[textbuffercounter] = 0;
      return textbuffer;
    } else if (status == 2) {
      textbuffer[textbuffercounter] = ' ';
      textbuffercounter++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<morse2text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %cl,-0xd(%rbp)
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0xd(%rbp),%al
lea    -0x18(%rbp),%r8
movsbl %al,%edx
movsbl -0xe(%rbp),%ecx
call   1030 <stringcutter@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <tablelookup@plt>
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%dl
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    122f <morse2text+0xef>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret
cmpl   $0x2,-0x18(%rbp)
jne    124e <morse2text+0x10e>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <morse2text+0x113>
jmp    118d <morse2text+0x4d>

x86 assembly (clang, -O2):
<morse2text>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%rbx
movl   $0x1,0xc(%rsp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %r12d,%r12d
movsbl %r15b,%eax
mov    %eax,0x14(%rsp)
movsbl %bpl,%eax
mov    %eax,0x10(%rsp)
jmp    1199 <morse2text+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x20,(%r14,%rcx,1)
add    $0x2,%r12d
mov    %r13d,%ebp
mov    %rbx,%rdi
mov    %r13d,%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xc(%rsp),%r8
call   1030 <stringcutter@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
not    %r13d
add    %ebp,%r13d
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <tablelookup@plt>
movslq %r12d,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x1,%rcx
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     1190 <morse2text+0x50>
mov    %ecx,%r12d
test   %eax,%eax
jne    1199 <morse2text+0x59>
movb   $0x0,(%r14,%rcx,1)
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @morse2text(i8* %0, i32 %1, i8 signext %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%15 = load i32, i32* %6
store i32 %15, i32* %9
store i32 1, i32* %10
store i32 0, i32* %11
store i8 0, i8* %12
%16 = call i8* @malloc(i32 1024)
store i8* %16, i8** %13
%17 = call i8* @malloc(i32 1024)
store i8* %17, i8** %14
br label %18
18: ; preds = %4, %63
%19 = load i8*, i8** %5
%20 = load i32, i32* %9
%21 = load i8, i8* %7
%22 = load i8, i8* %8
%23 = call i8* @stringcutter(i8* %19, i32 %20, i8 signext %21, i8 signext %22, i32* %10)
store i8* %23, i8** %13
%24 = load i32, i32* %9
%25 = load i8*, i8** %13
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %24, %26
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %9
%29 = load i8*, i8** %5
%30 = load i8*, i8** %13
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %5
%35 = load i8*, i8** %13
%36 = call signext i8 @tablelookup(i8* %35)
store i8 %36, i8* %12
%37 = load i8, i8* %12
%38 = load i8*, i8** %14
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %18
%47 = load i8*, i8** %14
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %14
ret i8* %51
52: ; preds = %18
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, 2
br i1 %54, label %55, label %62
55: ; preds = %52
%56 = load i8*, i8** %14
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 32, i8* %59
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %62
62: ; preds = %55, %52
br label %63
63: ; preds = %62
br label %18
}

LLVM IR (-O2):
define noalias i8* @morse2text(i8* %0, i32 %1, i8 signext %2, i8 signext %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%7 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
br label %8
8: ; preds = %25, %4
%9 = phi i32 [ %1, %4 ], [ %15, %25 ]
%10 = phi i32 [ 0, %4 ], [ %26, %25 ]
%11 = phi i8* [ %0, %4 ], [ %19, %25 ]
%12 = call i8* @stringcutter(i8* %11, i32 %9, i8 signext %2, i8 signext %3, i32* %5)
%13 = call i32 @strlen(i8* %12)
%14 = xor i32 %13, -1
%15 = add i32 %9, %14
%16 = call i32 @strlen(i8* %12)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %11, i64 1
%19 = getelementptr inbounds i8, i8* %18, i64 %17
%20 = call signext i8 @tablelookup(i8* %12)
%21 = sext i32 %10 to i64
%22 = getelementptr inbounds i8, i8* %7, i64 %21
store i8 %20, i8* %22
%23 = add nsw i32 %10, 1
%24 = load i32, i32* %5
switch i32 %24, label %25 [
i32 0, label %27
i32 2, label %30
]
25: ; preds = %8, %30
%26 = phi i32 [ %23, %8 ], [ %33, %30 ]
br label %8
27: ; preds = %8
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds i8, i8* %7, i64 %28
store i8 0, i8* %29
ret i8* %7
30: ; preds = %8
%31 = sext i32 %23 to i64
%32 = getelementptr inbounds i8, i8* %7, i64 %31
store i8 32, i8* %32
%33 = add nsw i32 %10, 2
br label %25
}