#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*/ uart_puts(char *);
void change_rtc_second(int value) {
  if (!(value >= 0 && value <= 59)) {
    uart_puts("\nError: Second must between 0 to 59!");
    return;
  }
  int low = value % 10;
  int high = value / 10;
  (*(volatile unsigned int *)(0x7E005040)) |= (1 << 3);
  (*(volatile unsigned int *)(0x7E005040)) = 1;
  (*(volatile unsigned int *)(0x7E005070)) = (high << 4) | low;
  (*(volatile unsigned int *)(0x7E005040)) = 0;
  return;
}


x86 assembly (clang, -O0):
<change_rtc_second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     112f <change_rtc_second+0x1f>
cmpl   $0x3b,-0x4(%rbp)
jle    1140 <change_rtc_second+0x30>
lea    0xeca(%rip),%rdi
call   1030 <uart_puts@plt>
jmp    1193 <change_rtc_second+0x83>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    $0x7e005040,%eax
mov    (%rax),%ecx
or     $0x8,%ecx
mov    $0x7e005040,%eax
mov    %ecx,(%rax)
mov    $0x7e005040,%eax
movl   $0x1,(%rax)
mov    -0xc(%rbp),%ecx
shl    $0x4,%ecx
or     -0x8(%rbp),%ecx
mov    $0x7e005070,%eax
mov    %ecx,(%rax)
mov    $0x7e005040,%eax
movl   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_rtc_second>:
cmp    $0x3c,%edi
jae    1158 <change_rtc_second+0x48>
movzbl %dil,%eax
imul   $0xcd,%eax,%ecx
shr    $0xb,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %dl,%al
movzbl %al,%eax
orl    $0x8,0x7e005040
08
movl   $0x1,0x7e005040
shl    $0x4,%ecx
or     %eax,%ecx
mov    %ecx,0x7e005070
movl   $0x0,0x7e005040
ret
lea    0xea1(%rip),%rdi
jmp    1030 <uart_puts@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"\0AError: Second must between 0 to 59!\00"
define void @change_rtc_second(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 59
br i1 %9, label %12, label %10
10: ; preds = %7, %1
%11 = call i32 @uart_puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %23
12: ; preds = %7
%13 = load i32, i32* %2
%14 = srem i32 %13, 10
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 10
store i32 %16, i32* %4
%17 = load volatile i32, i32* inttoptr (i64 2113949760 to i32*)
%18 = or i32 %17, 8
store volatile i32 %18, i32* inttoptr (i64 2113949760 to i32*)
store volatile i32 1, i32* inttoptr (i64 2113949760 to i32*)
%19 = load i32, i32* %4
%20 = shl i32 %19, 4
%21 = load i32, i32* %3
%22 = or i32 %20, %21
store volatile i32 %22, i32* inttoptr (i64 2113949808 to i32*)
store volatile i32 0, i32* inttoptr (i64 2113949760 to i32*)
br label %23
23: ; preds = %12, %10
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"\0AError: Second must between 0 to 59!\00"
define void @change_rtc_second(i32 %0) {
%2 = icmp ult i32 %0, 60
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @uart_puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %15
5: ; preds = %1
%6 = trunc i32 %0 to i8
%7 = urem i8 %6, 10
%8 = zext i8 %7 to i32
%9 = udiv i8 %6, 10
%10 = zext i8 %9 to i32
%11 = load volatile i32, i32* inttoptr (i64 2113949760 to i32*)
%12 = or i32 %11, 8
store volatile i32 %12, i32* inttoptr (i64 2113949760 to i32*)
store volatile i32 1, i32* inttoptr (i64 2113949760 to i32*)
%13 = shl nuw nsw i32 %10, 4
%14 = or i32 %13, %8
store volatile i32 %14, i32* inttoptr (i64 2113949808 to i32*)
store volatile i32 0, i32* inttoptr (i64 2113949760 to i32*)
br label %15
15: ; preds = %5, %3
ret void
}