#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*/ DS3231_Write(int, int);
int decimal_to_bcd(unsigned char);
void setTime(unsigned char hSet, unsigned char mSet, unsigned char sSet,
             short am_pm_state, short hour_format) {
  unsigned char tmp = 0;
  DS3231_Write(0x00, (decimal_to_bcd(sSet)));
  DS3231_Write(0x01, (decimal_to_bcd(mSet)));
  switch (hour_format) {
  case 1: {
    switch (am_pm_state) {
    case 1: {
      tmp = 0x60;
      break;
    }
    default: {
      tmp = 0x40;
      break;
    }
    }
    DS3231_Write(0x02, ((tmp | (0x1F & (decimal_to_bcd(hSet))))));
    break;
  }
  default: {
    DS3231_Write(0x02, (0x3F & (decimal_to_bcd(hSet))));
    break;
  }
  }
}


x86 assembly (clang, -O0):
<setTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %r8w,%ax
mov    %dil,-0x1(%rbp)
mov    %sil,-0x2(%rbp)
mov    %dl,-0x3(%rbp)
mov    %cx,-0x6(%rbp)
mov    %ax,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movzbl -0x3(%rbp),%edi
call   1030 <decimal_to_bcd@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1040 <DS3231_Write@plt>
movzbl -0x2(%rbp),%edi
call   1030 <decimal_to_bcd@plt>
mov    %eax,%esi
mov    $0x1,%edi
call   1040 <DS3231_Write@plt>
mov    -0x8(%rbp),%ax
sub    $0x1,%ax
jne    11c4 <setTime+0xa4>
jmp    117d <setTime+0x5d>
mov    -0x6(%rbp),%ax
sub    $0x1,%ax
jne    1199 <setTime+0x79>
jmp    1190 <setTime+0x70>
movb   $0x60,-0x9(%rbp)
jmp    119d <setTime+0x7d>
movb   $0x40,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
movzbl -0x1(%rbp),%edi
call   1030 <decimal_to_bcd@plt>
mov    -0x10(%rbp),%esi
and    $0x1f,%eax
or     %eax,%esi
mov    $0x2,%edi
call   1040 <DS3231_Write@plt>
jmp    11dc <setTime+0xbc>
movzbl -0x1(%rbp),%edi
call   1030 <decimal_to_bcd@plt>
mov    %eax,%esi
and    $0x3f,%esi
mov    $0x2,%edi
call   1040 <DS3231_Write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setTime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %esi,%ebx
mov    %edi,%r15d
mov    %edx,%edi
call   1030 <decimal_to_bcd@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <DS3231_Write@plt>
mov    %ebx,%edi
call   1030 <decimal_to_bcd@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1040 <DS3231_Write@plt>
cmp    $0x1,%bp
jne    117c <setTime+0x5c>
xor    %ebx,%ebx
cmp    $0x1,%r14w
sete   %bl
shl    $0x5,%ebx
movzbl %r15b,%edi
call   1030 <decimal_to_bcd@plt>
and    $0x1f,%eax
lea    (%rbx,%rax,1),%esi
add    $0x40,%esi
jmp    118a <setTime+0x6a>
movzbl %r15b,%edi
call   1030 <decimal_to_bcd@plt>
mov    %eax,%esi
and    $0x3f,%esi
mov    $0x2,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <DS3231_Write@plt>

LLVM IR (-O0):
define void @setTime(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i16 signext %3, i16 signext %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i16
%10 = alloca i16
%11 = alloca i8
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i16 %3, i16* %9
store i16 %4, i16* %10
store i8 0, i8* %11
%12 = load i8, i8* %8
%13 = call i32 @decimal_to_bcd(i8 zeroext %12)
%14 = call i32 @DS3231_Write(i32 0, i32 %13)
%15 = load i8, i8* %7
%16 = call i32 @decimal_to_bcd(i8 zeroext %15)
%17 = call i32 @DS3231_Write(i32 1, i32 %16)
%18 = load i16, i16* %10
%19 = sext i16 %18 to i32
switch i32 %19, label %33 [
i32 1, label %20
]
20: ; preds = %5
%21 = load i16, i16* %9
%22 = sext i16 %21 to i32
switch i32 %22, label %24 [
i32 1, label %23
]
23: ; preds = %20
store i8 96, i8* %11
br label %25
24: ; preds = %20
store i8 64, i8* %11
br label %25
25: ; preds = %24, %23
%26 = load i8, i8* %11
%27 = zext i8 %26 to i32
%28 = load i8, i8* %6
%29 = call i32 @decimal_to_bcd(i8 zeroext %28)
%30 = and i32 31, %29
%31 = or i32 %27, %30
%32 = call i32 @DS3231_Write(i32 2, i32 %31)
br label %38
33: ; preds = %5
%34 = load i8, i8* %6
%35 = call i32 @decimal_to_bcd(i8 zeroext %34)
%36 = and i32 63, %35
%37 = call i32 @DS3231_Write(i32 2, i32 %36)
br label %38
38: ; preds = %33, %25
ret void
}

LLVM IR (-O2):
define void @setTime(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i16 signext %3, i16 signext %4) {
%6 = tail call i32 @decimal_to_bcd(i8 zeroext %2)
%7 = tail call i32 @DS3231_Write(i32 0, i32 %6)
%8 = tail call i32 @decimal_to_bcd(i8 zeroext %1)
%9 = tail call i32 @DS3231_Write(i32 1, i32 %8)
%10 = icmp eq i16 %4, 1
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = icmp eq i16 %3, 1
%13 = select i1 %12, i32 96, i32 64
%14 = tail call i32 @decimal_to_bcd(i8 zeroext %0)
%15 = and i32 %14, 31
%16 = or i32 %15, %13
br label %20
17: ; preds = %5
%18 = tail call i32 @decimal_to_bcd(i8 zeroext %0)
%19 = and i32 %18, 63
br label %20
20: ; preds = %17, %11
%21 = phi i32 [ %19, %17 ], [ %16, %11 ]
%22 = tail call i32 @DS3231_Write(i32 2, i32 %21)
ret void
}