#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 */
int /*<<< orphan*/ *append(char *, char const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
char *translate(char const);
char *morse(const char *s, const char *delim) {
  static char buf[512];
  *buf = '\0';
  const char *p;
  for (p = s; *p; p++) {
    if (strlen(buf) > 0 && append(buf, delim, 512) == NULL) {
      fprintf(stderr, "Morse translation of %s is too long\n", s);
      return NULL;
    }
    char *m;
    if ((m = translate(*p)) == NULL) {
      fprintf(stderr, "No morse translation for %c in %s\n", *p, s);
      return NULL;
    }
    if (append(buf, m, 512) == NULL) {
      fprintf(stderr, "Morse translation of %s is too long\n", s);
      return NULL;
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<morse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,0x2ef9(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     126f <morse+0x12f>
lea    0x2edd(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11c9 <morse+0x89>
mov    -0x18(%rbp),%rsi
lea    0x2ec3(%rip),%rdi
mov    $0x200,%edx
call   1030 <append@plt>
cmp    $0x0,%rax
jne    11c9 <morse+0x89>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <morse+0x13a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1060 <translate@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1212 <morse+0xd2>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
mov    -0x10(%rbp),%rcx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <morse+0x13a>
mov    -0x28(%rbp),%rsi
lea    0x2e33(%rip),%rdi
mov    $0x200,%edx
call   1030 <append@plt>
cmp    $0x0,%rax
jne    1259 <morse+0x119>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <morse+0x13a>
jmp    125e <morse+0x11e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <morse+0x1f>
lea    0x2dda(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movb   $0x0,0x2f00(%rip)
mov    (%rdi),%bl
test   %bl,%bl
je     11c8 <morse+0x88>
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x2eed(%rip),%r12
mov    %rdi,%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1197 <morse+0x57>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x200,%edx
call   1030 <append@plt>
test   %rax,%rax
je     11d1 <morse+0x91>
movzbl 0x0(%r13),%ebx
movsbl %bl,%edi
call   1060 <translate@plt>
test   %rax,%rax
je     11f0 <morse+0xb0>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x200,%edx
call   1030 <append@plt>
test   %rax,%rax
je     11d1 <morse+0x91>
movzbl 0x1(%r13),%ebx
add    $0x1,%r13
test   %bl,%bl
jne    1170 <morse+0x30>
jmp    1212 <morse+0xd2>
lea    0x2e81(%rip),%r12
jmp    1212 <morse+0xd2>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1212 <morse+0xd2>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
movsbl 0x0(%r13),%edx
lea    0xe20(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@morse.buf = internal global [512 x i8] zeroinitializer
@stderr = global i32 0
@.str = [37 x i8] c"Morse translation of %s is too long\0A\00"
@.str.1 = [35 x i8] c"No morse translation for %c in %s\0A\00"
define i8* @morse(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0)
%8 = load i8*, i8** %4
store i8* %8, i8** %6
br label %9
9: ; preds = %45, %2
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = call i64 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0))
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i32* @append(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), i8* %17, i32 512)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %22)
store i8* null, i8** %3
br label %49
24: ; preds = %16, %13
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = call i8* @translate(i8 signext %26)
store i8* %27, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = load i8*, i8** %4
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %34)
store i8* null, i8** %3
br label %49
36: ; preds = %24
%37 = load i8*, i8** %7
%38 = call i32* @append(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), i8* %37, i32 512)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %4
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %42)
store i8* null, i8** %3
br label %49
44: ; preds = %36
br label %45
45: ; preds = %44
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %6
br label %9
48: ; preds = %9
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), i8** %3
br label %49
49: ; preds = %48, %40, %29, %20
%50 = load i8*, i8** %3
ret i8* %50
}

LLVM IR (-O2):
@morse.buf = internal global [512 x i8] zeroinitializer
@stderr = global i32 0
@.str = [37 x i8] c"Morse translation of %s is too long\0A\00"
@.str.1 = [35 x i8] c"No morse translation for %c in %s\0A\00"
define i8* @morse(i8* %0, i8* %1) {
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %37, label %5
5: ; preds = %2, %33
%6 = phi i8 [ %35, %33 ], [ %3, %2 ]
%7 = phi i8* [ %34, %33 ], [ %0, %2 ]
%8 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0))
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = tail call i32* @append(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), i8* %1, i32 512)
%12 = icmp eq i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = load i8, i8* %7
br label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %37
18: ; preds = %13, %5
%19 = phi i8 [ %14, %13 ], [ %6, %5 ]
%20 = tail call i8* @translate(i8 signext %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8, i8* %7
%25 = sext i8 %24 to i32
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %0)
br label %37
27: ; preds = %18
%28 = tail call i32* @append(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), i8* %20, i32 512)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %37
33: ; preds = %27
%34 = getelementptr inbounds i8, i8* %7, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %5
37: ; preds = %33, %2, %22, %30, %15
%38 = phi i8* [ null, %15 ], [ null, %30 ], [ null, %22 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), %2 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @morse.buf, i64 0, i64 0), %33 ]
ret i8* %38
}