#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 strlen(char *);
int /*<<< orphan*/ video_append_header(char *);
int /*<<< orphan*/ video_clear();
int /*<<< orphan*/ video_gotoxy(int, int);
int /*<<< orphan*/ video_print(char const *);
int /*<<< orphan*/ video_printcolor(char *, int, int);
void __PANIC(const char *msg) {
  video_clear();
  video_gotoxy(80 / 2 - strlen("KERNEL PANIC") / 2 - 1, 12);
  video_printcolor("KERNEL PANIC", 0x04, 0x0F);
  video_gotoxy(0, 1);
  video_print(msg);
  video_append_header("KERNEL PANIC");
  while (1) {
  };
}


x86 assembly (clang, -O0):
<__PANIC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <video_clear@plt>
lea    0xe86(%rip),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x28,%edi
sub    %eax,%edi
sub    $0x1,%edi
mov    $0xc,%esi
call   1080 <video_gotoxy@plt>
lea    0xe5e(%rip),%rdi
mov    $0x4,%esi
mov    $0xf,%edx
call   1050 <video_printcolor@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1080 <video_gotoxy@plt>
mov    -0x8(%rbp),%rdi
call   1060 <video_print@plt>
lea    0xe33(%rip),%rdi
call   1070 <video_append_header@plt>
jmp    11d2 <__PANIC+0x72>

x86 assembly (clang, -O2):
<__PANIC>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <video_clear@plt>
lea    0xe8b(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    $0x27,%edi
sub    %ecx,%edi
mov    $0xc,%esi
call   1080 <video_gotoxy@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0xf,%edx
call   1050 <video_printcolor@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1080 <video_gotoxy@plt>
mov    %r14,%rdi
call   1060 <video_print@plt>
mov    %rbx,%rdi
call   1070 <video_append_header@plt>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    11d0 <__PANIC+0x70>

LLVM IR (-O0):
@.str = [13 x i8] c"KERNEL PANIC\00"
define void @__PANIC(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (...) @video_clear()
%4 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = sdiv i32 %4, 2
%6 = sub nsw i32 40, %5
%7 = sub nsw i32 %6, 1
%8 = call i32 @video_gotoxy(i32 %7, i32 12)
%9 = call i32 @video_printcolor(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 4, i32 15)
%10 = call i32 @video_gotoxy(i32 0, i32 1)
%11 = load i8*, i8** %2
%12 = call i32 @video_print(i8* %11)
%13 = call i32 @video_append_header(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %1, %14
br label %14
}

LLVM IR (-O2):
@.str = [13 x i8] c"KERNEL PANIC\00"
define void @__PANIC(i8* %0) {
%2 = tail call i32 (...) @video_clear()
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = sdiv i32 %3, -2
%5 = add nsw i32 %4, 39
%6 = tail call i32 @video_gotoxy(i32 %5, i32 12)
%7 = tail call i32 @video_printcolor(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 4, i32 15)
%8 = tail call i32 @video_gotoxy(i32 0, i32 1)
%9 = tail call i32 @video_print(i8* %0)
%10 = tail call i32 @video_append_header(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %1, %11
br label %11
}