#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;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(size_t const);
int /*<<< orphan*/ snprintf(char *, size_t const, char *, int, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *Sys_create_time_str(bool const inDate, bool const inSeconds) {
  char *retVal = NULL;
  time_t t = time(NULL);
  struct tm const *const l = localtime(&t);
  size_t const dateLen = 11, timeLen = 5;
  size_t len = timeLen + 1, pos = 0;
  if (inDate) {
    len += dateLen;
  }
  if (inSeconds) {
    len += 3;
  }
  size_t const byteLen = len * (sizeof *retVal);
  retVal = malloc(byteLen);
  assert(retVal != NULL);
  if (inDate) {
    snprintf(retVal + pos, byteLen - pos, "%d/%02d/%02d-", l->tm_year + 1900,
             l->tm_mon + 1, l->tm_mday);
    pos += dateLen;
  }
  snprintf(retVal + pos, byteLen - pos, "%02d:%02d", l->tm_hour, l->tm_min);
  pos += timeLen;
  if (inSeconds) {
    snprintf(retVal + pos, byteLen - pos, ":%02d", l->tm_sec);
  }
  return retVal;
}


x86 assembly (clang, -O0):
<Sys_create_time_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
movq   $0xb,-0x28(%rbp)
movq   $0x5,-0x30(%rbp)
movq   $0x6,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11b5 <Sys_create_time_str+0x65>
mov    -0x38(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11cb <Sys_create_time_str+0x7b>
mov    -0x38(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0x0,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x0,-0x4(%rbp)
je     124a <Sys_create_time_str+0xfa>
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
sub    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r9d
lea    0xdc9(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
sub    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r8d
lea    0xd9e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12b2 <Sys_create_time_str+0x162>
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
sub    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%ecx
lea    0xd67(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_create_time_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r12d
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%r13
test   %r12d,%r12d
mov    $0x6,%eax
mov    $0x11,%ecx
cmove  %rax,%rcx
lea    0x3(%rcx),%rbp
test   %r14d,%r14d
cmove  %rcx,%rbp
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
test   %r12d,%r12d
je     11e3 <Sys_create_time_str+0x93>
mov    $0x76c,%ecx
add    0x0(%r13),%ecx
mov    0x4(%r13),%r8d
mov    0x8(%r13),%r9d
add    $0x1,%r8d
lea    0xe2f(%rip),%rdx
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    $0xb,%ebx
lea    (%r15,%rbx,1),%rdi
mov    %rbp,%rsi
sub    %rbx,%rsi
mov    0xc(%r13),%ecx
mov    0x10(%r13),%r8d
lea    0xe12(%rip),%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %r14d,%r14d
je     122a <Sys_create_time_str+0xda>
add    $0x5,%rbx
mov    %r15,%rdi
add    %rbx,%rdi
sub    %rbx,%rbp
mov    0x14(%r13),%ecx
lea    0xdf2(%rip),%rdx
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [14 x i8] c"%d/%02d/%02d-\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [6 x i8] c":%02d\00"
define i8* @Sys_create_time_str(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* null, i8** %5
%13 = call i32 @time(i32* null)
store i32 %13, i32* %6
%14 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %14, %struct.tm** %7
store i64 11, i64* %8
store i64 5, i64* %9
store i64 6, i64* %10
store i64 0, i64* %11
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i64, i64* %10
%19 = add i64 %18, 11
store i64 %19, i64* %10
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i64, i64* %10
%25 = add i64 %24, 3
store i64 %25, i64* %10
br label %26
26: ; preds = %23, %20
%27 = load i64, i64* %10
%28 = mul i64 %27, 1
store i64 %28, i64* %12
%29 = load i64, i64* %12
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %3
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %26
%38 = load i8*, i8** %5
%39 = load i64, i64* %11
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i64, i64* %12
%42 = load i64, i64* %11
%43 = sub i64 %41, %42
%44 = load %struct.tm*, %struct.tm** %7
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1900
%48 = load %struct.tm*, %struct.tm** %7
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 1
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
%52 = load %struct.tm*, %struct.tm** %7
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %40, i64 %43, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %51, i32 %54)
%56 = load i64, i64* %11
%57 = add i64 %56, 11
store i64 %57, i64* %11
br label %58
58: ; preds = %37, %26
%59 = load i8*, i8** %5
%60 = load i64, i64* %11
%61 = getelementptr inbounds i8, i8* %59, i64 %60
%62 = load i64, i64* %12
%63 = load i64, i64* %11
%64 = sub i64 %62, %63
%65 = load %struct.tm*, %struct.tm** %7
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 3
%67 = load i32, i32* %66
%68 = load %struct.tm*, %struct.tm** %7
%69 = getelementptr inbounds %struct.tm, %struct.tm* %68, i32 0, i32 4
%70 = load i32, i32* %69
%71 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %61, i64 %64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %67, i32 %70)
%72 = load i64, i64* %11
%73 = add i64 %72, 5
store i64 %73, i64* %11
%74 = load i32, i32* %4
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %87
76: ; preds = %58
%77 = load i8*, i8** %5
%78 = load i64, i64* %11
%79 = getelementptr inbounds i8, i8* %77, i64 %78
%80 = load i64, i64* %12
%81 = load i64, i64* %11
%82 = sub i64 %80, %81
%83 = load %struct.tm*, %struct.tm** %7
%84 = getelementptr inbounds %struct.tm, %struct.tm* %83, i32 0, i32 5
%85 = load i32, i32* %84
%86 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %79, i64 %82, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %76, %58
%88 = load i8*, i8** %5
ret i8* %88
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [14 x i8] c"%d/%02d/%02d-\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [6 x i8] c":%02d\00"
define i8* @Sys_create_time_str(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %3
%6 = call %struct.tm* @localtime(i32* %3)
%7 = icmp eq i32 %0, 0
%8 = select i1 %7, i64 6, i64 17
%9 = icmp eq i32 %1, 0
%10 = add nuw nsw i64 %8, 3
%11 = select i1 %9, i64 %8, i64 %10
%12 = call i8* @malloc(i64 %11)
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
br i1 %7, label %26, label %16
16: ; preds = %2
%17 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1900
%20 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
%23 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %12, i64 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22, i32 %24)
br label %26
26: ; preds = %16, %2
%27 = phi i64 [ 11, %16 ], [ 0, %2 ]
%28 = getelementptr inbounds i8, i8* %12, i64 %27
%29 = sub nsw i64 %11, %27
%30 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 4
%33 = load i32, i32* %32
%34 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %28, i64 %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %33)
%35 = add nuw nsw i64 %27, 5
br i1 %9, label %42, label %36
36: ; preds = %26
%37 = getelementptr inbounds i8, i8* %12, i64 %35
%38 = sub nsw i64 %11, %35
%39 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 5
%40 = load i32, i32* %39
%41 = call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %37, i64 %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %36, %26
ret i8* %12
}