#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_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *get_hextime(int is_capped) {
  char *hextime;
  hextime = malloc(6);
  time_t rawtime;
  rawtime = time(NULL);
  struct tm *timeinfo = localtime(&rawtime);
  if (is_capped)
    sprintf(hextime, "%X:%X:%X\n", timeinfo->tm_hour, timeinfo->tm_min,
            timeinfo->tm_sec);
  else
    sprintf(hextime, "%x:%x:%x\n", timeinfo->tm_hour, timeinfo->tm_min,
            timeinfo->tm_sec);
  return hextime;
}


x86 assembly (clang, -O0):
<get_hextime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a6 <get_hextime+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe64(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11cb <get_hextime+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe44(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hextime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %ebp,%ebp
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
lea    0xe91(%rip),%rax
lea    0xe80(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [10 x i8] c"%X:%X:%X\0A\00"
@.str.1 = [10 x i8] c"%x:%x:%x\0A\00"
define i8* @get_hextime(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
store i32 %0, i32* %2
%6 = call i8* @malloc(i32 6)
store i8* %6, i8** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %4
%8 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %8, %struct.tm** %5
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load %struct.tm*, %struct.tm** %5
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load %struct.tm*, %struct.tm** %5
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load %struct.tm*, %struct.tm** %5
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 2
%21 = load i32, i32* %20
%22 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %18, i32 %21)
br label %35
23: ; preds = %1
%24 = load i8*, i8** %3
%25 = load %struct.tm*, %struct.tm** %5
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load %struct.tm*, %struct.tm** %5
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %5
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %30, i32 %33)
br label %35
35: ; preds = %23, %11
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [10 x i8] c"%X:%X:%X\0A\00"
@.str.1 = [10 x i8] c"%x:%x:%x\0A\00"
define noalias i8* @get_hextime(i32 %0) {
%2 = alloca i32
%3 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @localtime(i32* %2)
%7 = icmp eq i32 %0, 0
%8 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%13 = load i32, i32* %12
%14 = select i1 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0)
%15 = call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) %14, i32 %9, i32 %11, i32 %13)
ret i8* %3
}