#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*/ serial_write_str(char *);
int /*<<< orphan*/ strcpy(char *, char *);
void serial_debug_print(unsigned int severity, char *buf) {
  char sevstr[(9)];
  switch (severity) {
  case 0:
    strcpy(sevstr, "FATAL: ");
    break;
  case 1:
    strcpy(sevstr, "ERROR: ");
    break;
  case 2:
    strcpy(sevstr, "WARNG: ");
    break;
  case 3:
    strcpy(sevstr, "INFOR: ");
    break;
  case 4:
  default:
    strcpy(sevstr, "DEBUG: ");
    break;
  }
  serial_write_str(sevstr);
  serial_write_str(buf);
}


x86 assembly (clang, -O0):
<serial_debug_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x4,%rax
ja     11ad <serial_debug_print+0x8d>
mov    -0x28(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x19(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bd <serial_debug_print+0x9d>
lea    -0x19(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bd <serial_debug_print+0x9d>
lea    -0x19(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bd <serial_debug_print+0x9d>
lea    -0x19(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bd <serial_debug_print+0x9d>
jmp    11ad <serial_debug_print+0x8d>
lea    -0x19(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x19(%rbp),%rdi
call   1040 <serial_write_str@plt>
mov    -0x10(%rbp),%rdi
call   1040 <serial_write_str@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_debug_print>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
ja     1142 <serial_debug_print+0x22>
movslq %edi,%rax
lea    0xeef(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    1149 <serial_debug_print+0x29>
lea    0xed7(%rip),%rsi
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <serial_write_str@plt>
mov    %r14,%rdi
call   1040 <serial_write_str@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"FATAL: \00"
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [8 x i8] c"WARNG: \00"
@.str.3 = [8 x i8] c"INFOR: \00"
@.str.4 = [8 x i8] c"DEBUG: \00"
define void @serial_debug_print(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [9 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
switch i32 %6, label %20 [
i32 0, label %7
i32 1, label %10
i32 2, label %13
i32 3, label %16
i32 4, label %19
]
7: ; preds = %2
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %23
10: ; preds = %2
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %2
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %23
16: ; preds = %2
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
19: ; preds = %2
br label %20
20: ; preds = %2, %19
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %20, %16, %13, %10, %7
%24 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%25 = call i32 @serial_write_str(i8* %24)
%26 = load i8*, i8** %4
%27 = call i32 @serial_write_str(i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"FATAL: \00"
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [8 x i8] c"WARNG: \00"
@.str.3 = [8 x i8] c"INFOR: \00"
@.str.4 = [8 x i8] c"DEBUG: \00"
@reltable.serial_debug_print = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.serial_debug_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.serial_debug_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.serial_debug_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.serial_debug_print to i64)) to i32)]
define void @serial_debug_print(i32 %0, i8* %1) {
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%5 = icmp ult i32 %0, 4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = sext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.serial_debug_print to i8*), i64 %8)
br label %10
10: ; preds = %2, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %2 ]
%12 = call i32 @strcpy(i8* %4, i8* %11)
%13 = call i32 @serial_write_str(i8* %4)
%14 = call i32 @serial_write_str(i8* %1)
ret void
}