#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);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strdup(char *);
int strlen(char *);
char *default_message_type_katcm(char *string, int type) {
  int len;
  char *ptr;
  if (string == NULL) {
    return NULL;
  }
  switch (string[0]) {
  case '?':
  case '!':
  case '#':
    return strdup(string);
  }
  len = strlen(string);
  ptr = malloc(len + 2);
  if (ptr == NULL) {
    return NULL;
  }
  ptr[0] = type;
  memcpy(ptr + 1, string, len + 1);
  return ptr;
}


x86 assembly (clang, -O0):
<default_message_type_katcm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1167 <default_message_type_katcm+0x27>
movq   $0x0,-0x8(%rbp)
jmp    1210 <default_message_type_katcm+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x21,%eax
je     11a1 <default_message_type_katcm+0x61>
jmp    117f <default_message_type_katcm+0x3f>
mov    -0x24(%rbp),%eax
sub    $0x23,%eax
je     11a1 <default_message_type_katcm+0x61>
jmp    1190 <default_message_type_katcm+0x50>
mov    -0x24(%rbp),%eax
sub    $0x3f,%eax
jne    11b3 <default_message_type_katcm+0x73>
jmp    11a1 <default_message_type_katcm+0x61>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1210 <default_message_type_katcm+0xd0>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e6 <default_message_type_katcm+0xa6>
movq   $0x0,-0x8(%rbp)
jmp    1210 <default_message_type_katcm+0xd0>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_message_type_katcm>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b3 <default_message_type_katcm+0x73>
mov    %esi,%r14d
mov    %rdi,%rbx
movsbl (%rdi),%eax
cmp    $0x3f,%eax
ja     117c <default_message_type_katcm+0x3c>
movabs $0x8000000a00000000,%rcx
bt     %rax,%rcx
jae    117c <default_message_type_katcm+0x3c>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <strdup@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0x2(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b3 <default_message_type_katcm+0x73>
mov    %rax,%rbp
mov    %r14b,(%rax)
mov    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%r15d
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
jmp    11b5 <default_message_type_katcm+0x75>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @default_message_type_katcm(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %40
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %19 [
i32 63, label %16
i32 33, label %16
i32 35, label %16
]
16: ; preds = %11, %11, %11
%17 = load i8*, i8** %4
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %3
br label %40
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 2
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %19
store i8* null, i8** %3
br label %40
28: ; preds = %19
%29 = load i32, i32* %5
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 %30, i8* %32
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
%38 = call i32 @memcpy(i8* %34, i8* %35, i32 %37)
%39 = load i8*, i8** %7
store i8* %39, i8** %3
br label %40
40: ; preds = %28, %27, %16, %10
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
define i8* @default_message_type_katcm(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
switch i32 %6, label %9 [
i32 63, label %7
i32 33, label %7
i32 35, label %7
]
7: ; preds = %4, %4, %4
%8 = tail call i8* @strdup(i8* %0)
br label %19
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %0)
%11 = add nsw i32 %10, 2
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = trunc i32 %1 to i8
store i8 %15, i8* %12
%16 = getelementptr inbounds i8, i8* %12, i64 1
%17 = add nsw i32 %10, 1
%18 = tail call i32 @memcpy(i8* %16, i8* %0, i32 %17)
br label %19
19: ; preds = %9, %2, %14, %7
%20 = phi i8* [ %12, %14 ], [ %8, %7 ], [ null, %2 ], [ null, %9 ]
ret i8* %20
}