#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 */
typedef scalar_t__ time_t;
struct tm {
  scalar_t__ tm_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
  scalar_t__ tm_mday;
  scalar_t__ tm_mon;
  scalar_t__ tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ time(scalar_t__ *);
char to_bcd(scalar_t__);
void package_set_device_clock_value(char *buffer) {
  struct tm time_struct;
  time_t curr_time;
  time(&curr_time);
  if (((time_t)-1) == curr_time) {
    printf("?? Can't get time\n");
    return;
  }
  localtime_r(&curr_time, &time_struct);
  memset(buffer, 0, 17 - 1);
  buffer[0x00] = 0x5a;
  buffer[0x01] = 0x01;
  buffer[0x02] = to_bcd(time_struct.tm_year - 100);
  buffer[0x03] = to_bcd(time_struct.tm_mon + 1);
  buffer[0x04] = to_bcd(time_struct.tm_mday);
  buffer[0x05] = to_bcd(time_struct.tm_hour);
  buffer[0x06] = to_bcd(time_struct.tm_min);
  buffer[0x07] = to_bcd(time_struct.tm_sec);
}


x86 assembly (clang, -O0):
<package_set_device_clock_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <time@plt>
mov    $0xffffffffffffffff,%rax
cmp    -0x40(%rbp),%rax
jne    1187 <package_set_device_clock_value+0x37>
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
jmp    1227 <package_set_device_clock_value+0xd7>
lea    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
movb   $0x5a,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x1,0x1(%rax)
mov    -0x10(%rbp),%rdi
sub    $0x64,%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x20(%rbp),%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x28(%rbp),%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x30(%rbp),%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x38(%rbp),%rdi
call   1070 <to_bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<package_set_device_clock_value>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1060 <time@plt>
cmpq   $0xffffffffffffffff,0x8(%rsp)
je     11e5 <package_set_device_clock_value+0x95>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movw   $0x15a,(%rbx)
mov    0x38(%rsp),%rdi
add    $0xffffffffffffff9c,%rdi
call   1070 <to_bcd@plt>
mov    %al,0x2(%rbx)
mov    0x30(%rsp),%rdi
add    $0x1,%rdi
call   1070 <to_bcd@plt>
mov    %al,0x3(%rbx)
mov    0x28(%rsp),%rdi
call   1070 <to_bcd@plt>
mov    %al,0x4(%rbx)
mov    0x20(%rsp),%rdi
call   1070 <to_bcd@plt>
mov    %al,0x5(%rbx)
mov    0x18(%rsp),%rdi
call   1070 <to_bcd@plt>
mov    %al,0x6(%rbx)
mov    0x10(%rsp),%rdi
call   1070 <to_bcd@plt>
mov    %al,0x7(%rbx)
jmp    11f1 <package_set_device_clock_value+0xa1>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64, i64, i64, i64 }
@.str = [19 x i8] c"?? Can't get time\0A\00"
define void @package_set_device_clock_value(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = alloca i64
store i8* %0, i8** %2
%5 = call i32 @time(i64* %4)
%6 = load i64, i64* %4
%7 = icmp eq i64 -1, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %50
10: ; preds = %1
%11 = call i32 @localtime_r(i64* %4, %struct.tm* %3)
%12 = load i8*, i8** %2
%13 = call i32 @memset(i8* %12, i32 0, i32 16)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 90, i8* %15
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 1, i8* %17
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 5
%19 = load i64, i64* %18
%20 = sub nsw i64 %19, 100
%21 = call signext i8 @to_bcd(i64 %20)
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8 %21, i8* %23
%24 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 4
%25 = load i64, i64* %24
%26 = add nsw i64 %25, 1
%27 = call signext i8 @to_bcd(i64 %26)
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 3
store i8 %27, i8* %29
%30 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 3
%31 = load i64, i64* %30
%32 = call signext i8 @to_bcd(i64 %31)
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 4
store i8 %32, i8* %34
%35 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
%36 = load i64, i64* %35
%37 = call signext i8 @to_bcd(i64 %36)
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 5
store i8 %37, i8* %39
%40 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
%41 = load i64, i64* %40
%42 = call signext i8 @to_bcd(i64 %41)
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 6
store i8 %42, i8* %44
%45 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
%46 = load i64, i64* %45
%47 = call signext i8 @to_bcd(i64 %46)
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 7
store i8 %47, i8* %49
br label %50
50: ; preds = %10, %8
ret void
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i64, i64, i64 }
@str = [18 x i8] c"?? Can't get time\00"
define void @package_set_device_clock_value(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca i64
%4 = bitcast %struct.tm* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @time(i64* %3)
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %41
11: ; preds = %1
%12 = call i32 @localtime_r(i64* %3, %struct.tm* %2)
%13 = call i32 @memset(i8* %0, i32 0, i32 16)
store i8 90, i8* %0
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 1, i8* %14
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
%16 = load i64, i64* %15
%17 = add nsw i64 %16, -100
%18 = call signext i8 @to_bcd(i64 %17)
%19 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %18, i8* %19
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
%21 = load i64, i64* %20
%22 = add nsw i64 %21, 1
%23 = call signext i8 @to_bcd(i64 %22)
%24 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %23, i8* %24
%25 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%26 = load i64, i64* %25
%27 = call signext i8 @to_bcd(i64 %26)
%28 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %27, i8* %28
%29 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%30 = load i64, i64* %29
%31 = call signext i8 @to_bcd(i64 %30)
%32 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %31, i8* %32
%33 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%34 = load i64, i64* %33
%35 = call signext i8 @to_bcd(i64 %34)
%36 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %35, i8* %36
%37 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%38 = load i64, i64* %37
%39 = call signext i8 @to_bcd(i64 %38)
%40 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %39, i8* %40
br label %41
41: ; preds = %11, %9
ret void
}