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

/* Variables and functions */
int asprintf(char **, char *, int, scalar_t__, int /*<<< orphan*/,
             int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *gentime_string_from_tm(struct tm *tm) {
  char *ret = NULL;
  int year;
  year = tm->tm_year + 1900;
  if (year < 0 || year > 9999)
    return (NULL);
  if (asprintf(&ret, "%04u%02u%02u%02u%02u%02uZ", year, tm->tm_mon + 1,
               tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec) == -1)
    ret = NULL;
  return (ret);
}


x86 assembly (clang, -O0):
<gentime_string_from_tm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1149 <gentime_string_from_tm+0x39>
cmpl   $0x270f,-0x1c(%rbp)
jle    1156 <gentime_string_from_tm+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <gentime_string_from_tm+0xa5>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r10d
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
lea    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11ad <gentime_string_from_tm+0x9d>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gentime_string_from_tm>:
push   %rax
movq   $0x0,(%rsp)
mov    (%rdi),%edx
lea    -0x1fa4(%rdx),%eax
cmp    $0xffffd8f0,%eax
jb     1166 <gentime_string_from_tm+0x56>
add    $0x76c,%edx
mov    0x18(%rdi),%rcx
add    $0x1,%rcx
mov    0x10(%rdi),%r8d
mov    0xc(%rdi),%r9d
mov    0x4(%rdi),%eax
mov    0x8(%rdi),%r10d
lea    0xeb4(%rip),%rsi
mov    %rsp,%rdi
push   %rax
push   %r10
call   1030 <asprintf@plt>
add    $0x10,%rsp
cmp    $0xffffffff,%eax
je     1166 <gentime_string_from_tm+0x56>
mov    (%rsp),%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i64 }
@.str = [26 x i8] c"%04u%02u%02u%02u%02u%02uZ\00"
define i8* @gentime_string_from_tm(%struct.tm* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %3
store i8* null, i8** %4
%6 = load %struct.tm*, %struct.tm** %3
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1900
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 9999
br i1 %14, label %15, label %16
15: ; preds = %12, %1
store i8* null, i8** %2
br label %39
16: ; preds = %12
%17 = load i32, i32* %5
%18 = load %struct.tm*, %struct.tm** %3
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 5
%20 = load i64, i64* %19
%21 = add nsw i64 %20, 1
%22 = load %struct.tm*, %struct.tm** %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 4
%24 = load i32, i32* %23
%25 = load %struct.tm*, %struct.tm** %3
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 3
%27 = load i32, i32* %26
%28 = load %struct.tm*, %struct.tm** %3
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 2
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %3
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %17, i64 %21, i32 %24, i32 %27, i32 %30, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %16
store i8* null, i8** %4
br label %37
37: ; preds = %36, %16
%38 = load i8*, i8** %4
store i8* %38, i8** %2
br label %39
39: ; preds = %37, %15
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i64 }
@.str = [26 x i8] c"%04u%02u%02u%02u%02u%02uZ\00"
define i8* @gentime_string_from_tm(%struct.tm* nocapture %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = add i32 %5, -8100
%7 = icmp ult i32 %6, -10000
br i1 %7, label %25, label %8
8: ; preds = %1
%9 = add nsw i32 %5, 1900
%10 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%11 = load i64, i64* %10
%12 = add nsw i64 %11, 1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9, i64 %12, i32 %14, i32 %16, i32 %18, i32 %20)
%22 = icmp eq i32 %21, -1
%23 = load i8*, i8** %2
%24 = select i1 %22, i8* null, i8* %23
br label %25
25: ; preds = %8, %1
%26 = phi i8* [ null, %1 ], [ %24, %8 ]
ret i8* %26
}