void panic(const char *file, const char *function, int line,
           const char *message) {
  irq_disable();
  char *line_as_string = "     ";
  int_to_string(line, line_as_string);
  unsigned char print_attribute = (0x4 << 4) | ((0x7 | 0x08) & 0xF);
  clear_screen_clr(print_attribute);
  print_clr("================================ Kernel Panic!! "
            "================================\n\n",
            print_attribute);
  print_clr("The kernel encountered an error from which it could not recover. "
            "This could be due to hardware issues, but is most likely due to a "
            "kernel bug.\n\n",
            print_attribute);
  char line_buffer[256];
  snprintf(line_buffer, 256, "Location: %s:%d (in function '%s')\n", 3, file,
           line, function);
  print_clr(line_buffer, print_attribute);
  if (message) {
    print_clr("Message: ", print_attribute);
    print_clr(message, print_attribute);
  }
  __asm__ __volatile__("hlt");
}


x86 assembly (clang, -O0):
<panic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1050 <irq_disable@plt>
lea    0xe88(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1070 <int_to_string@plt>
movb   $0x4f,-0x29(%rbp)
movzbl -0x29(%rbp),%edi
mov    $0x0,%al
call   1060 <clear_screen_clr@plt>
movzbl -0x29(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <print_clr@plt>
movzbl -0x29(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <print_clr@plt>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    -0x10(%rbp),%rax
mov    $0x100,%esi
lea    0xf0e(%rip),%rdx
mov    $0x3,%ecx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rdi
movzbl -0x29(%rbp),%esi
mov    $0x0,%al
call   1030 <print_clr@plt>
cmpq   $0x0,-0x20(%rbp)
je     122a <panic+0xda>
movzbl -0x29(%rbp),%esi
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <print_clr@plt>
mov    -0x20(%rbp),%rdi
movzbl -0x29(%rbp),%esi
mov    $0x0,%al
call   1030 <print_clr@plt>
hlt
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<panic>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <irq_disable@plt>
lea    0xe8a(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1070 <int_to_string@plt>
mov    $0x4f,%edi
xor    %eax,%eax
call   1060 <clear_screen_clr@plt>
lea    0xe74(%rip),%rdi
mov    $0x4f,%esi
xor    %eax,%eax
call   1030 <print_clr@plt>
lea    0xeb4(%rip),%rdi
mov    $0x4f,%esi
xor    %eax,%eax
call   1030 <print_clr@plt>
mov    %rbx,(%rsp)
lea    0xf2e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    $0x100,%esi
mov    %rbx,%rdi
mov    $0x3,%ecx
mov    %r15,%r8
mov    %ebp,%r9d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x4f,%esi
xor    %eax,%eax
call   1030 <print_clr@plt>
test   %r14,%r14
je     1211 <panic+0xc1>
lea    0xf18(%rip),%rdi
mov    $0x4f,%esi
xor    %eax,%eax
call   1030 <print_clr@plt>
mov    %r14,%rdi
mov    $0x4f,%esi
xor    %eax,%eax
call   1030 <print_clr@plt>
hlt
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c" \00"
@.str.1 = [83 x i8] c"================================ Kernel Panic!! ================================\0A\0A\00"
@.str.2 = [145 x i8] c"The kernel encountered an error from which it could not recover. This could be due to hardware issues, but is most likely due to a kernel bug.\0A\0A\00"
@.str.3 = [36 x i8] c"Location: %s:%d (in function '%s')\0A\00"
@.str.4 = [10 x i8] c"Message: \00"
define void @panic(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = call i32 (...) @irq_disable()
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9
%13 = load i32, i32* %7
%14 = load i8*, i8** %9
%15 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @int_to_string to i32 (i32, i8*, ...)*)(i32 %13, i8* %14)
store i8 79, i8* %10
%16 = load i8, i8* %10
%17 = zext i8 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @clear_screen_clr to i32 (i32, ...)*)(i32 %17)
%19 = load i8, i8* %10
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %10
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = load i32, i32* %7
%28 = load i8*, i8** %6
%29 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %25, i64 256, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 3, i8* %26, i32 %27, i8* %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%31 = load i8, i8* %10
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* %30, i32 %32)
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %44
36: ; preds = %4
%37 = load i8, i8* %10
%38 = zext i8 %37 to i32
%39 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %8
%41 = load i8, i8* %10
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* %40, i32 %42)
br label %44
44: ; preds = %36, %4
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" \00"
@.str.1 = [83 x i8] c"================================ Kernel Panic!! ================================\0A\0A\00"
@.str.2 = [145 x i8] c"The kernel encountered an error from which it could not recover. This could be due to hardware issues, but is most likely due to a kernel bug.\0A\0A\00"
@.str.3 = [36 x i8] c"Location: %s:%d (in function '%s')\0A\00"
@.str.4 = [10 x i8] c"Message: \00"
define void @panic(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = tail call i32 (...) @irq_disable()
%7 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @int_to_string to i32 (i32, i8*, ...)*)(i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @clear_screen_clr to i32 (i32, ...)*)(i32 79)
%9 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.1, i64 0, i64 0), i32 79)
%10 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.2, i64 0, i64 0), i32 79)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %11, i64 256, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 3, i8* %0, i32 %2, i8* %1)
%13 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* %11, i32 79)
%14 = icmp eq i8* %3, null
br i1 %14, label %18, label %15
15: ; preds = %4
%16 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 79)
%17 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_clr to i32 (i8*, i32, ...)*)(i8* %3, i32 79)
br label %18
18: ; preds = %15, %4
ret void
}