#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 morse_encode(char);
char *char2morse(char ch, char *morse) {
  char encoding = 0;
  char *retval = morse;
  unsigned char counter = 0;
  unsigned char code = 0;
  static const unsigned char mask = 0x80;
  if (morse == NULL)
    return morse;
  encoding = morse_encode(ch);
  counter = (encoding & 0x7);
  code = (encoding & 0xf8);
  for (; counter > 0; counter--) {
    if (mask & code) {
      *morse = '-';
    } else {
      *morse = '.';
    }
    code <<= 1;
    morse++;
  }
  *morse = 0;
  return retval;
}


x86 assembly (clang, -O0):
<char2morse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movb   $0x0,-0x2a(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <char2morse+0x3e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <char2morse+0xc4>
movsbl -0x9(%rbp),%edi
call   1030 <morse_encode@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
and    $0x7,%eax
mov    %al,-0x29(%rbp)
movsbl -0x19(%rbp),%eax
and    $0xf8,%eax
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jle    11c5 <char2morse+0xb5>
movzbl -0x2a(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     119b <char2morse+0x8b>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
jmp    11a2 <char2morse+0x92>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
movzbl -0x2a(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x2a(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x29(%rbp),%al
add    $0xff,%al
mov    %al,-0x29(%rbp)
jmp    1170 <char2morse+0x60>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char2morse>:
push   %rbx
mov    %rsi,%rbx
test   %rsi,%rsi
je     11d4 <char2morse+0xc4>
movsbl %dil,%edi
call   1030 <morse_encode@plt>
mov    %eax,%ecx
mov    %rbx,%rdx
and    $0x7,%cl
je     11d1 <char2morse+0xc1>
mov    %eax,%edx
sar    $0x7,%dl
add    $0x2e,%dl
mov    %dl,(%rbx)
cmp    $0x1,%cl
jne    114c <char2morse+0x3c>
lea    0x1(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
mov    %eax,%edx
and    $0x40,%dl
cmp    $0x1,%dl
mov    $0x2d,%sil
mov    $0x2d,%dl
adc    $0x0,%dl
mov    %dl,0x1(%rbx)
cmp    $0x2,%cl
jne    116a <char2morse+0x5a>
lea    0x2(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
mov    %eax,%edx
and    $0x20,%dl
cmp    $0x1,%dl
adc    $0x0,%sil
mov    %sil,0x2(%rbx)
cmp    $0x3,%cl
jne    1185 <char2morse+0x75>
lea    0x3(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
mov    %eax,%edx
and    $0x10,%dl
cmp    $0x1,%dl
mov    $0x2d,%sil
mov    $0x2d,%dl
adc    $0x0,%dl
mov    %dl,0x3(%rbx)
cmp    $0x4,%cl
jne    11a3 <char2morse+0x93>
lea    0x4(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
and    $0x8,%al
cmp    $0x1,%al
adc    $0x0,%sil
mov    %sil,0x4(%rbx)
cmp    $0x5,%cl
jne    11ba <char2morse+0xaa>
lea    0x5(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
movb   $0x2e,0x5(%rbx)
cmp    $0x6,%cl
jne    11c9 <char2morse+0xb9>
lea    0x6(%rbx),%rdx
jmp    11d1 <char2morse+0xc1>
movb   $0x2e,0x6(%rbx)
lea    0x7(%rbx),%rdx
movb   $0x0,(%rdx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@char2morse.mask = internal constant i8 -128
define i8* @char2morse(i8 signext %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
store i8 %0, i8* %4
store i8* %1, i8** %5
store i8 0, i8* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %7
store i8 0, i8* %8
store i8 0, i8* %9
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i8*, i8** %5
store i8* %14, i8** %3
br label %52
15: ; preds = %2
%16 = load i8, i8* %4
%17 = call signext i8 @morse_encode(i8 signext %16)
store i8 %17, i8* %6
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = and i32 %19, 7
%21 = trunc i32 %20 to i8
store i8 %21, i8* %8
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = and i32 %23, 248
%25 = trunc i32 %24 to i8
store i8 %25, i8* %9
br label %26
26: ; preds = %46, %15
%27 = load i8, i8* %8
%28 = zext i8 %27 to i32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %26
%31 = load i8, i8* %9
%32 = zext i8 %31 to i32
%33 = and i32 128, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i8*, i8** %5
store i8 45, i8* %36
br label %39
37: ; preds = %30
%38 = load i8*, i8** %5
store i8 46, i8* %38
br label %39
39: ; preds = %37, %35
%40 = load i8, i8* %9
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 1
%43 = trunc i32 %42 to i8
store i8 %43, i8* %9
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
br label %46
46: ; preds = %39
%47 = load i8, i8* %8
%48 = add i8 %47, -1
store i8 %48, i8* %8
br label %26
49: ; preds = %26
%50 = load i8*, i8** %5
store i8 0, i8* %50
%51 = load i8*, i8** %7
store i8* %51, i8** %3
br label %52
52: ; preds = %49, %13
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
define i8* @char2morse(i8 signext %0, i8* returned writeonly %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %44, label %4
4: ; preds = %2
%5 = tail call signext i8 @morse_encode(i8 signext %0)
%6 = and i8 %5, 7
%7 = icmp eq i8 %6, 0
br i1 %7, label %42, label %8
8: ; preds = %4
%9 = icmp sgt i8 %5, -1
%10 = select i1 %9, i8 46, i8 45
store i8 %10, i8* %1
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = icmp eq i8 %6, 1
br i1 %12, label %42, label %13
13: ; preds = %8
%14 = and i8 %5, 64
%15 = icmp eq i8 %14, 0
%16 = select i1 %15, i8 46, i8 45
store i8 %16, i8* %11
%17 = getelementptr inbounds i8, i8* %1, i64 2
%18 = icmp eq i8 %6, 2
br i1 %18, label %42, label %19
19: ; preds = %13
%20 = and i8 %5, 32
%21 = icmp eq i8 %20, 0
%22 = select i1 %21, i8 46, i8 45
store i8 %22, i8* %17
%23 = getelementptr inbounds i8, i8* %1, i64 3
%24 = icmp eq i8 %6, 3
br i1 %24, label %42, label %25
25: ; preds = %19
%26 = and i8 %5, 16
%27 = icmp eq i8 %26, 0
%28 = select i1 %27, i8 46, i8 45
store i8 %28, i8* %23
%29 = getelementptr inbounds i8, i8* %1, i64 4
%30 = icmp eq i8 %6, 4
br i1 %30, label %42, label %31
31: ; preds = %25
%32 = and i8 %5, 8
%33 = icmp eq i8 %32, 0
%34 = select i1 %33, i8 46, i8 45
store i8 %34, i8* %29
%35 = getelementptr inbounds i8, i8* %1, i64 5
%36 = icmp eq i8 %6, 5
br i1 %36, label %42, label %37
37: ; preds = %31
store i8 46, i8* %35
%38 = getelementptr inbounds i8, i8* %1, i64 6
%39 = icmp eq i8 %6, 6
br i1 %39, label %42, label %40
40: ; preds = %37
store i8 46, i8* %38
%41 = getelementptr inbounds i8, i8* %1, i64 7
br label %42
42: ; preds = %8, %13, %19, %25, %31, %37, %40, %4
%43 = phi i8* [ %1, %4 ], [ %11, %8 ], [ %17, %13 ], [ %23, %19 ], [ %29, %25 ], [ %35, %31 ], [ %38, %37 ], [ %41, %40 ]
store i8 0, i8* %43
br label %44
44: ; preds = %2, %42
ret i8* %1
}