#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 */
struct regs {
  int dummy;
};

/* Variables and functions */
int clock_get_uptime();
int cmos_get_hours();
int cmos_get_minutes();
int cmos_get_seconds();
int /*<<< orphan*/ int_to_string(int, char *);
int port_byte_in(int);
int /*<<< orphan*/ print(char *);
void keyboard_handler(struct regs *r) {
  int data = port_byte_in(0x60);
  if ((data & 0x80) == 0) {
    int uptime = clock_get_uptime();
    char *buf = "               ";
    int_to_string(uptime, buf);
    print("The current time is ");
    int_to_string(cmos_get_hours(), buf);
    print(buf);
    print(":");
    int_to_string(cmos_get_minutes(), buf);
    print(buf);
    print(":");
    int_to_string(cmos_get_seconds(), buf);
    print(buf);
  }
}


x86 assembly (clang, -O0):
<keyboard_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x60,%edi
call   1070 <port_byte_in@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1230 <keyboard_handler+0xc0>
mov    $0x0,%al
call   1050 <clock_get_uptime@plt>
mov    %eax,-0x10(%rbp)
lea    0xe55(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <int_to_string@plt>
lea    0xe4e(%rip),%rdi
call   1040 <print@plt>
mov    $0x0,%al
call   1090 <cmos_get_hours@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1080 <int_to_string@plt>
mov    -0x18(%rbp),%rdi
call   1040 <print@plt>
lea    0xe3c(%rip),%rdi
call   1040 <print@plt>
mov    $0x0,%al
call   1030 <cmos_get_minutes@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1080 <int_to_string@plt>
mov    -0x18(%rbp),%rdi
call   1040 <print@plt>
lea    0xe15(%rip),%rdi
call   1040 <print@plt>
mov    $0x0,%al
call   1060 <cmos_get_seconds@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1080 <int_to_string@plt>
mov    -0x18(%rbp),%rdi
call   1040 <print@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyboard_handler>:
push   %r14
push   %rbx
push   %rax
mov    $0x60,%edi
call   1070 <port_byte_in@plt>
test   $0x80,%al
jne    1213 <keyboard_handler+0xa3>
xor    %eax,%eax
call   1050 <clock_get_uptime@plt>
lea    0xe6c(%rip),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <int_to_string@plt>
lea    0xe6b(%rip),%rdi
call   1040 <print@plt>
xor    %eax,%eax
call   1090 <cmos_get_hours@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <int_to_string@plt>
mov    %rbx,%rdi
call   1040 <print@plt>
lea    0xe5b(%rip),%r14
mov    %r14,%rdi
call   1040 <print@plt>
xor    %eax,%eax
call   1030 <cmos_get_minutes@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <int_to_string@plt>
mov    %rbx,%rdi
call   1040 <print@plt>
mov    %r14,%rdi
call   1040 <print@plt>
xor    %eax,%eax
call   1060 <cmos_get_seconds@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <int_to_string@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <print@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.regs = type { i32 }
@.str = [16 x i8] c" \00"
@.str.1 = [21 x i8] c"The current time is \00"
@.str.2 = [2 x i8] c":\00"
define void @keyboard_handler(%struct.regs* %0) {
%2 = alloca %struct.regs*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store %struct.regs* %0, %struct.regs** %2
%6 = call i32 @port_byte_in(i32 96)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = and i32 %7, 128
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %1
%11 = call i32 (...) @clock_get_uptime()
store i32 %11, i32* %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %5
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = call i32 @int_to_string(i32 %12, i8* %13)
%15 = call i32 @print(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (...) @cmos_get_hours()
%17 = load i8*, i8** %5
%18 = call i32 @int_to_string(i32 %16, i8* %17)
%19 = load i8*, i8** %5
%20 = call i32 @print(i8* %19)
%21 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (...) @cmos_get_minutes()
%23 = load i8*, i8** %5
%24 = call i32 @int_to_string(i32 %22, i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @print(i8* %25)
%27 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (...) @cmos_get_seconds()
%29 = load i8*, i8** %5
%30 = call i32 @int_to_string(i32 %28, i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @print(i8* %31)
br label %33
33: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
%struct.regs = type { i32 }
@.str = [16 x i8] c" \00"
@.str.1 = [21 x i8] c"The current time is \00"
@.str.2 = [2 x i8] c":\00"
define void @keyboard_handler(%struct.regs* nocapture readnone %0) {
%2 = tail call i32 @port_byte_in(i32 96)
%3 = and i32 %2, 128
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %1
%6 = tail call i32 (...) @clock_get_uptime()
%7 = tail call i32 @int_to_string(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @print(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 (...) @cmos_get_hours()
%10 = tail call i32 @int_to_string(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @print(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 (...) @cmos_get_minutes()
%14 = tail call i32 @int_to_string(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @print(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 (...) @cmos_get_seconds()
%18 = tail call i32 @int_to_string(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @print(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %5, %1
ret void
}