#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*/ __kern_rtc_tget(char *, char *, char *);
int /*<<< orphan*/ __kern_rtc_tset(char, char, char);
int /*<<< orphan*/ kprintf(char *, ...);
scalar_t__ ksscanf(char *, char *, ...);
void __kern_shell_time(char *cstr) {
  char h, m, s;
  int ih, im, is;
  if (ksscanf(cstr, "time %d:%d:%d", &ih, &im, &is)) {
    kprintf("Setting clock to %02d:%02d:%02d\n", ih, im, is);
    __kern_rtc_tset((char)ih, (char)im, (char)is);
  } else if (ksscanf(cstr, "time")) {
    __kern_rtc_tget(&h, &m, &s);
    kprintf("Current time: %02d:%02d:%02d\n", h, m, s);
  } else {
    kprintf("%s: command syntax error\n", cstr);
  }
}


x86 assembly (clang, -O0):
<__kern_shell_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
mov    $0x0,%al
call   1060 <ksscanf@plt>
cmp    $0x0,%rax
je     11ab <__kern_shell_time+0x6b>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%eax
movsbl %dl,%edi
movsbl %cl,%esi
movsbl %al,%edx
call   1030 <__kern_rtc_tset@plt>
jmp    120e <__kern_shell_time+0xce>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <ksscanf@plt>
cmp    $0x0,%rax
je     11f7 <__kern_shell_time+0xb7>
lea    -0x9(%rbp),%rdi
lea    -0xa(%rbp),%rsi
lea    -0xb(%rbp),%rdx
call   1040 <__kern_rtc_tget@plt>
movsbl -0x9(%rbp),%esi
movsbl -0xa(%rbp),%edx
movsbl -0xb(%rbp),%ecx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
jmp    1209 <__kern_shell_time+0xc9>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
jmp    120e <__kern_shell_time+0xce>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__kern_shell_time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
xor    %eax,%eax
call   1060 <ksscanf@plt>
test   %rax,%rax
je     119a <__kern_shell_time+0x5a>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
movsbl 0xc(%rsp),%edi
movsbl 0x8(%rsp),%esi
movsbl 0x4(%rsp),%edx
call   1030 <__kern_rtc_tset@plt>
jmp    11f4 <__kern_shell_time+0xb4>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <ksscanf@plt>
test   %rax,%rax
je     11e3 <__kern_shell_time+0xa3>
lea    0x3(%rsp),%rdi
lea    0x2(%rsp),%rsi
lea    0x1(%rsp),%rdx
call   1040 <__kern_rtc_tget@plt>
movsbl 0x3(%rsp),%esi
movsbl 0x2(%rsp),%edx
movsbl 0x1(%rsp),%ecx
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
jmp    11f4 <__kern_shell_time+0xb4>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <kprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"time %d:%d:%d\00"
@.str.1 = [33 x i8] c"Setting clock to %02d:%02d:%02d\0A\00"
@.str.2 = [5 x i8] c"time\00"
@.str.3 = [30 x i8] c"Current time: %02d:%02d:%02d\0A\00"
@.str.4 = [26 x i8] c"%s: command syntax error\0A\00"
define void @__kern_shell_time(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 (i8*, i8*, ...) @ksscanf(i8* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %1
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %15)
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %7
%20 = trunc i32 %19 to i8
%21 = load i32, i32* %8
%22 = trunc i32 %21 to i8
%23 = call i32 @__kern_rtc_tset(i8 signext %18, i8 signext %20, i8 signext %22)
br label %41
24: ; preds = %1
%25 = load i8*, i8** %2
%26 = call i64 (i8*, i8*, ...) @ksscanf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = call i32 @__kern_rtc_tget(i8* %3, i8* %4, i8* %5)
%30 = load i8, i8* %3
%31 = sext i8 %30 to i32
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %35)
br label %40
37: ; preds = %24
%38 = load i8*, i8** %2
%39 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %28
br label %41
41: ; preds = %40, %12
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"time %d:%d:%d\00"
@.str.1 = [33 x i8] c"Setting clock to %02d:%02d:%02d\0A\00"
@.str.2 = [5 x i8] c"time\00"
@.str.3 = [30 x i8] c"Current time: %02d:%02d:%02d\0A\00"
@.str.4 = [26 x i8] c"%s: command syntax error\0A\00"
define void @__kern_shell_time(i8* %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = call i64 (i8*, i8*, ...) @ksscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %1
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %5
%19 = trunc i32 %18 to i8
%20 = load i32, i32* %6
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %7
%23 = trunc i32 %22 to i8
%24 = call i32 @__kern_rtc_tset(i8 signext %19, i8 signext %21, i8 signext %23)
br label %39
25: ; preds = %1
%26 = call i64 (i8*, i8*, ...) @ksscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %37, label %28
28: ; preds = %25
%29 = call i32 @__kern_rtc_tget(i8* %2, i8* %3, i8* %4)
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = load i8, i8* %4
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %35)
br label %39
37: ; preds = %25
%38 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %39
39: ; preds = %28, %37, %13
ret void
}