#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 DS3231_Read(int);
unsigned char bcd_to_decimal(unsigned char);
void getTime(unsigned char *p3, unsigned char *p2, unsigned char *p1,
             unsigned char *p0, unsigned char hour_format) {
  unsigned char tmp = 0;
  tmp = DS3231_Read(0x00);
  *p1 = bcd_to_decimal(tmp);
  tmp = DS3231_Read(0x01);
  *p2 = bcd_to_decimal(tmp);
  switch (hour_format) {
  case 1:
    tmp = DS3231_Read(0x02);
    tmp &= 0x20;
    *p0 = (unsigned char)(tmp >> 5);
    tmp = (0x1F & DS3231_Read(0x02));
    *p3 = bcd_to_decimal(tmp);
  default:
    tmp = (0x3F & DS3231_Read(0x02));
    *p3 = bcd_to_decimal(tmp);
    break;
  }
}


x86 assembly (clang, -O0):
<getTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movb   $0x0,-0x22(%rbp)
xor    %edi,%edi
call   1030 <DS3231_Read@plt>
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    $0x1,%edi
call   1030 <DS3231_Read@plt>
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x21(%rbp),%al
sub    $0x1,%al
jne    11d2 <getTime+0xb2>
jmp    118b <getTime+0x6b>
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%eax
and    $0x20,%eax
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%eax
sar    $0x5,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
and    $0x1f,%eax
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
and    $0x3f,%eax
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
xor    %edi,%edi
call   1030 <DS3231_Read@plt>
movzbl %al,%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,(%rbx)
mov    $0x1,%edi
call   1030 <DS3231_Read@plt>
movzbl %al,%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,0x0(%rbp)
cmp    $0x1,%r12b
jne    118c <getTime+0x6c>
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
shr    $0x5,%al
and    $0x1,%al
mov    %al,(%r14)
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
and    $0x1f,%eax
mov    %eax,%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,(%r15)
mov    $0x2,%edi
call   1030 <DS3231_Read@plt>
and    $0x3f,%eax
mov    %eax,%edi
call   1040 <bcd_to_decimal@plt>
mov    %al,(%r15)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @getTime(i8* %0, i8* %1, i8* %2, i8* %3, i8 zeroext %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8 %4, i8* %10
store i8 0, i8* %11
%12 = call i32 @DS3231_Read(i32 0)
%13 = trunc i32 %12 to i8
store i8 %13, i8* %11
%14 = load i8, i8* %11
%15 = call zeroext i8 @bcd_to_decimal(i8 zeroext %14)
%16 = load i8*, i8** %8
store i8 %15, i8* %16
%17 = call i32 @DS3231_Read(i32 1)
%18 = trunc i32 %17 to i8
store i8 %18, i8* %11
%19 = load i8, i8* %11
%20 = call zeroext i8 @bcd_to_decimal(i8 zeroext %19)
%21 = load i8*, i8** %7
store i8 %20, i8* %21
%22 = load i8, i8* %10
%23 = zext i8 %22 to i32
switch i32 %23, label %42 [
i32 1, label %24
]
24: ; preds = %5
%25 = call i32 @DS3231_Read(i32 2)
%26 = trunc i32 %25 to i8
store i8 %26, i8* %11
%27 = load i8, i8* %11
%28 = zext i8 %27 to i32
%29 = and i32 %28, 32
%30 = trunc i32 %29 to i8
store i8 %30, i8* %11
%31 = load i8, i8* %11
%32 = zext i8 %31 to i32
%33 = ashr i32 %32, 5
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %9
store i8 %34, i8* %35
%36 = call i32 @DS3231_Read(i32 2)
%37 = and i32 31, %36
%38 = trunc i32 %37 to i8
store i8 %38, i8* %11
%39 = load i8, i8* %11
%40 = call zeroext i8 @bcd_to_decimal(i8 zeroext %39)
%41 = load i8*, i8** %6
store i8 %40, i8* %41
br label %42
42: ; preds = %5, %24
%43 = call i32 @DS3231_Read(i32 2)
%44 = and i32 63, %43
%45 = trunc i32 %44 to i8
store i8 %45, i8* %11
%46 = load i8, i8* %11
%47 = call zeroext i8 @bcd_to_decimal(i8 zeroext %46)
%48 = load i8*, i8** %6
store i8 %47, i8* %48
br label %49
49: ; preds = %42
ret void
}

LLVM IR (-O2):
define void @getTime(i8* nocapture writeonly %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3, i8 zeroext %4) {
%6 = tail call i32 @DS3231_Read(i32 0)
%7 = trunc i32 %6 to i8
%8 = tail call zeroext i8 @bcd_to_decimal(i8 zeroext %7)
store i8 %8, i8* %2
%9 = tail call i32 @DS3231_Read(i32 1)
%10 = trunc i32 %9 to i8
%11 = tail call zeroext i8 @bcd_to_decimal(i8 zeroext %10)
store i8 %11, i8* %1
%12 = icmp eq i8 %4, 1
br i1 %12, label %13, label %22
13: ; preds = %5
%14 = tail call i32 @DS3231_Read(i32 2)
%15 = trunc i32 %14 to i8
%16 = lshr i8 %15, 5
%17 = and i8 %16, 1
store i8 %17, i8* %3
%18 = tail call i32 @DS3231_Read(i32 2)
%19 = trunc i32 %18 to i8
%20 = and i8 %19, 31
%21 = tail call zeroext i8 @bcd_to_decimal(i8 zeroext %20)
store i8 %21, i8* %0
br label %22
22: ; preds = %5, %13
%23 = tail call i32 @DS3231_Read(i32 2)
%24 = trunc i32 %23 to i8
%25 = and i8 %24, 63
%26 = tail call zeroext i8 @bcd_to_decimal(i8 zeroext %25)
store i8 %26, i8* %0
ret void
}