#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*/ kprintf(char *, ...);
int /*<<< orphan*/ timer_initialise();
int /*<<< orphan*/ timer_phase(int);
int /*<<< orphan*/ timer_wait(int);
void kmane(void) {
  int i;
  kprintf("%[1;34;44m%s%[;30;40m%[J", "Kernels are magic");
  timer_initialise();
  timer_phase(1000);
  for (i = 0;; i++) {
    timer_wait(1000);
    kprintf("%[H%[1;34;44m%i%[;30;40m%[K", i);
  }
}


x86 assembly (clang, -O0):
<kmane>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec3(%rip),%rsi
mov    $0x0,%al
call   1060 <kprintf@plt>
mov    $0x0,%al
call   1040 <timer_initialise@plt>
mov    $0x3e8,%edi
call   1030 <timer_phase@plt>
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1050 <timer_wait@plt>
mov    -0x4(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1060 <kprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <kmane+0x35>

x86 assembly (clang, -O2):
<kmane>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1060 <kprintf@plt>
xor    %eax,%eax
call   1040 <timer_initialise@plt>
mov    $0x3e8,%edi
call   1030 <timer_phase@plt>
lea    0xebb(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x3e8,%edi
call   1050 <timer_wait@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <kprintf@plt>
add    $0x1,%ebp
jmp    1180 <kmane+0x40>

LLVM IR (-O0):
@.str = [25 x i8] c"%[1;34;44m%s%[;30;40m%[J\00"
@.str.1 = [18 x i8] c"Kernels are magic\00"
@.str.2 = [28 x i8] c"%[H%[1;34;44m%i%[;30;40m%[K\00"
define void @kmane() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%3 = call i32 (...) @timer_initialise()
%4 = call i32 @timer_phase(i32 1000)
store i32 0, i32* %1
br label %5
5: ; preds = %9, %0
%6 = call i32 @timer_wait(i32 1000)
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %5
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
br label %5
}

LLVM IR (-O2):
@.str = [25 x i8] c"%[1;34;44m%s%[;30;40m%[J\00"
@.str.1 = [18 x i8] c"Kernels are magic\00"
@.str.2 = [28 x i8] c"%[H%[1;34;44m%i%[;30;40m%[K\00"
define void @kmane() {
%1 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (...) @timer_initialise()
%3 = tail call i32 @timer_phase(i32 1000)
br label %4
4: ; preds = %4, %0
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = tail call i32 @timer_wait(i32 1000)
%7 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%8 = add nuw nsw i32 %5, 1
br label %4
}