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

/* Variables and functions */
int /*<<< orphan*/ int_to_hex_2(int, unsigned char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int get_time(unsigned char *packed_data) {
  struct tm *t;
  time_t tt;
  time_t ts;
  struct tm tr = {0};
  int index = 0;
  int temp_date = 0;
  unsigned char temp[2] = {'\0'};
  time(&tt);
  t = localtime(&tt);
  int_to_hex_2((t->tm_year + 1900 - 2000), packed_data + index);
  printf("-----test ------ %x ---\r\n", packed_data[0]);
  printf("year is %d, %02x\r\n", (t->tm_year + 1900 - 2000),
         packed_data[index]);
  index++;
  int_to_hex_2((t->tm_mon + 1), packed_data + index);
  printf("mon is %d, %02x\r\n", (t->tm_mon + 1), (packed_data[index]));
  index++;
  int_to_hex_2(t->tm_mday, packed_data + index);
  index++;
  int_to_hex_2(t->tm_hour, packed_data + index);
  index++;
  int_to_hex_2(t->tm_min, packed_data + index);
  index++;
  int_to_hex_2(t->tm_sec, packed_data + index);
  index++;
  return index;
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1060 <memset@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
lea    -0x42(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
lea    -0x14(%rbp),%rdi
call   1070 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x76c,%edi
sub    $0x7d0,%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
add    $0x76c,%esi
sub    $0x7d0,%esi
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x8(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
call   1040 <int_to_hex_2@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    %rax,%r14
mov    (%rax),%edi
add    $0xffffff9c,%edi
mov    %rbx,%rsi
call   1040 <int_to_hex_2@plt>
movzbl (%rbx),%esi
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%esi
add    $0xffffff9c,%esi
movzbl (%rbx),%edx
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%r14),%edi
add    $0x1,%edi
lea    0x1(%rbx),%rsi
call   1040 <int_to_hex_2@plt>
mov    0x4(%r14),%esi
add    $0x1,%esi
movzbl 0x1(%rbx),%edx
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%edi
lea    0x2(%rbx),%rsi
call   1040 <int_to_hex_2@plt>
mov    0xc(%r14),%edi
lea    0x3(%rbx),%rsi
call   1040 <int_to_hex_2@plt>
mov    0x10(%r14),%edi
lea    0x4(%rbx),%rsi
call   1040 <int_to_hex_2@plt>
mov    0x14(%r14),%edi
add    $0x5,%rbx
mov    %rbx,%rsi
call   1040 <int_to_hex_2@plt>
mov    $0x6,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
@.str = [26 x i8] c"-----test ------ %x ---\0D\0A\00"
@.str.1 = [19 x i8] c"year is %d, %02x\0D\0A\00"
@.str.2 = [18 x i8] c"mon is %d, %02x\0D\0A\00"
define i32 @get_time(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
store i8* %0, i8** %2
%10 = bitcast %struct.tm* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
%11 = bitcast [2 x i8]* %9 to i8*
%12 = call i32 @time(i32* %4)
%13 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %13, %struct.tm** %3
%14 = load %struct.tm*, %struct.tm** %3
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
%18 = sub nsw i32 %17, 2000
%19 = load i8*, i8** %2
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @int_to_hex_2(i32 %18, i8* %22)
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load %struct.tm*, %struct.tm** %3
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1900
%33 = sub nsw i32 %32, 2000
%34 = load i8*, i8** %2
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
%43 = load %struct.tm*, %struct.tm** %3
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 1
%47 = load i8*, i8** %2
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = call i32 @int_to_hex_2(i32 %46, i8* %50)
%52 = load %struct.tm*, %struct.tm** %3
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
%56 = load i8*, i8** %2
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %61)
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
%65 = load %struct.tm*, %struct.tm** %3
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 2
%67 = load i32, i32* %66
%68 = load i8*, i8** %2
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = call i32 @int_to_hex_2(i32 %67, i8* %71)
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
%75 = load %struct.tm*, %struct.tm** %3
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 3
%77 = load i32, i32* %76
%78 = load i8*, i8** %2
%79 = load i32, i32* %7
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = call i32 @int_to_hex_2(i32 %77, i8* %81)
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
%85 = load %struct.tm*, %struct.tm** %3
%86 = getelementptr inbounds %struct.tm, %struct.tm* %85, i32 0, i32 4
%87 = load i32, i32* %86
%88 = load i8*, i8** %2
%89 = load i32, i32* %7
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = call i32 @int_to_hex_2(i32 %87, i8* %91)
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
%95 = load %struct.tm*, %struct.tm** %3
%96 = getelementptr inbounds %struct.tm, %struct.tm* %95, i32 0, i32 5
%97 = load i32, i32* %96
%98 = load i8*, i8** %2
%99 = load i32, i32* %7
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
%102 = call i32 @int_to_hex_2(i32 %97, i8* %101)
%103 = load i32, i32* %7
%104 = add nsw i32 %103, 1
store i32 %104, i32* %7
%105 = load i32, i32* %7
ret i32 %105
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
@.str = [26 x i8] c"-----test ------ %x ---\0D\0A\00"
@.str.1 = [19 x i8] c"year is %d, %02x\0D\0A\00"
@.str.2 = [18 x i8] c"mon is %d, %02x\0D\0A\00"
define i32 @get_time(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @time(i32* %2)
%5 = call %struct.tm* @localtime(i32* %2)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = add nsw i32 %7, -100
%9 = call i32 @int_to_hex_2(i32 %8, i8* %0)
%10 = load i8, i8* %0
%11 = zext i8 %10 to i32
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %6
%14 = add nsw i32 %13, -100
%15 = load i8, i8* %0
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %16)
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds i8, i8* %0, i64 1
%22 = call i32 @int_to_hex_2(i32 %20, i8* %21)
%23 = load i32, i32* %18
%24 = add nsw i32 %23, 1
%25 = load i8, i8* %21
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %26)
%28 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%29 = load i32, i32* %28
%30 = getelementptr inbounds i8, i8* %0, i64 2
%31 = call i32 @int_to_hex_2(i32 %29, i8* %30)
%32 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%33 = load i32, i32* %32
%34 = getelementptr inbounds i8, i8* %0, i64 3
%35 = call i32 @int_to_hex_2(i32 %33, i8* %34)
%36 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%37 = load i32, i32* %36
%38 = getelementptr inbounds i8, i8* %0, i64 4
%39 = call i32 @int_to_hex_2(i32 %37, i8* %38)
%40 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%41 = load i32, i32* %40
%42 = getelementptr inbounds i8, i8* %0, i64 5
%43 = call i32 @int_to_hex_2(i32 %41, i8* %42)
ret i32 6
}