#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_token_consume(char const *, char const **);
size_t morse_decode_fixed(char *buf, size_t buflen, char const *message) {
  char const *p = message;
  size_t i;
  for (i = 0; i + 1 < buflen && (buf[i] = morse_token_consume(p, &p)); ++i) {
  }
  while (morse_token_consume(p, &p)) {
    ++i;
  }
  return i;
}


x86 assembly (clang, -O0):
<morse_decode_fixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x29(%rbp)
jae    116f <morse_decode_fixed+0x5f>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <morse_token_consume@plt>
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    117f <morse_decode_fixed+0x6f>
jmp    1195 <morse_decode_fixed+0x85>
jmp    1184 <morse_decode_fixed+0x74>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1134 <morse_decode_fixed+0x24>
jmp    119a <morse_decode_fixed+0x8a>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <morse_token_consume@plt>
cmp    $0x0,%al
je     11c0 <morse_decode_fixed+0xb0>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119a <morse_decode_fixed+0x8a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morse_decode_fixed>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,0x8(%rsp)
cmp    $0x2,%rsi
mov    $0x1,%r13d
cmovb  %r13,%r14
sub    %r14,%r13
add    $0xffffffffffffffff,%r14
mov    $0xffffffffffffffff,%rbx
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
lea    (%rbx,%r13,1),%rax
cmp    $0xffffffffffffffff,%rax
je     1176 <morse_decode_fixed+0x66>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1030 <morse_token_consume@plt>
mov    %al,0x1(%r15,%rbx,1)
add    $0x1,%rbx
test   %al,%al
jne    1150 <morse_decode_fixed+0x40>
jmp    1179 <morse_decode_fixed+0x69>
mov    %r14,%rbx
add    $0xffffffffffffffff,%rbx
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <morse_token_consume@plt>
add    $0x1,%rbx
test   %al,%al
jne    1190 <morse_decode_fixed+0x80>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @morse_decode_fixed(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
store i8* %9, i8** %7
store i64 0, i64* %8
br label %10
10: ; preds = %26, %3
%11 = load i64, i64* %8
%12 = add i64 %11, 1
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i8*, i8** %7
%17 = call signext i8 @morse_token_consume(i8* %16, i8** %7)
%18 = load i8*, i8** %4
%19 = load i64, i64* %8
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8 %17, i8* %20
%21 = sext i8 %17 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %15, %10
%24 = phi i1 [ false, %10 ], [ %22, %15 ]
br i1 %24, label %25, label %29
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i64, i64* %8
%28 = add i64 %27, 1
store i64 %28, i64* %8
br label %10
29: ; preds = %23
br label %30
30: ; preds = %34, %29
%31 = load i8*, i8** %7
%32 = call signext i8 @morse_token_consume(i8* %31, i8** %7)
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
br label %30
37: ; preds = %30
%38 = load i64, i64* %8
ret i64 %38
}

LLVM IR (-O2):
define i64 @morse_decode_fixed(i8* nocapture writeonly %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* %2, i8** %4
%6 = call i64 @llvm.umax.i64(i64 %1, i64 1)
%7 = add i64 %6, -1
br label %8
8: ; preds = %11, %3
%9 = phi i64 [ 0, %3 ], [ %12, %11 ]
%10 = icmp eq i64 %9, %7
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = add nuw i64 %9, 1
%13 = load i8*, i8** %4
%14 = call signext i8 @morse_token_consume(i8* %13, i8** %4)
%15 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %14, i8* %15
%16 = icmp eq i8 %14, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %11
%18 = phi i64 [ %9, %11 ], [ %7, %8 ]
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ %24, %19 ], [ %18, %17 ]
%21 = load i8*, i8** %4
%22 = call signext i8 @morse_token_consume(i8* %21, i8** %4)
%23 = icmp eq i8 %22, 0
%24 = add i64 %20, 1
br i1 %23, label %25, label %19
25: ; preds = %19
ret i64 %20
}