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


x86 assembly (clang, -O0):
<change_rtc_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     112f <change_rtc_date+0x1f>
cmpl   $0x1f,-0x4(%rbp)
jle    1140 <change_rtc_date+0x30>
lea    0xeca(%rip),%rdi
call   1030 <uart_puts@plt>
jmp    1193 <change_rtc_date+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    $0x7e00507c,%eax
mov    %ecx,(%rax)
mov    $0x7e005040,%eax
movl   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_rtc_date>:
lea    -0x1(%rdi),%eax
cmp    $0x1f,%eax
jae    115b <change_rtc_date+0x4b>
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,0x7e00507c
movl   $0x0,0x7e005040
ret
lea    0xe9e(%rip),%rdi
jmp    1030 <uart_puts@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"\0AError: Date must between 1 to 31!\00"
define void @change_rtc_date(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, 1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 31
br i1 %9, label %12, label %10
10: ; preds = %7, %1
%11 = call i32 @uart_puts(i8* getelementptr inbounds ([35 x i8], [35 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 2113949820 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 = [35 x i8] c"\0AError: Date must between 1 to 31!\00"
define void @change_rtc_date(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 31
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @uart_puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %16
6: ; preds = %1
%7 = trunc i32 %0 to i8
%8 = urem i8 %7, 10
%9 = zext i8 %8 to i32
%10 = udiv i8 %7, 10
%11 = zext i8 %10 to i32
%12 = load volatile i32, i32* inttoptr (i64 2113949760 to i32*)
%13 = or i32 %12, 8
store volatile i32 %13, i32* inttoptr (i64 2113949760 to i32*)
store volatile i32 1, i32* inttoptr (i64 2113949760 to i32*)
%14 = shl nuw nsw i32 %11, 4
%15 = or i32 %14, %9
store volatile i32 %15, i32* inttoptr (i64 2113949820 to i32*)
store volatile i32 0, i32* inttoptr (i64 2113949760 to i32*)
br label %16
16: ; preds = %6, %4
ret void
}