#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 */
char *libewf_header_value_string_alloc(int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *libewf_generate_date_header_value(void) {
  char *date_string = libewf_header_value_string_alloc(20);
  time_t timestamp = time(NULL);
  struct tm *time_elements = localtime(&timestamp);
  snprintf(date_string, 20, "%4d %d %d %d %d %d",
           (time_elements->tm_year + 1900), (time_elements->tm_mon + 1),
           time_elements->tm_mday, time_elements->tm_hour,
           time_elements->tm_min, time_elements->tm_sec);
  return (date_string);
}


x86 assembly (clang, -O0):
<libewf_generate_date_header_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x14,%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
mov    $0x14,%esi
lea    0xe4a(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libewf_generate_date_header_value>:
push   %r14
push   %rbx
push   %rax
mov    $0x14,%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%ebx
mov    0x14(%rax),%eax
sub    $0x8,%rsp
lea    0xe72(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
push   %rax
push   %rbx
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"%4d %d %d %d %d %d\00"
define i8* @libewf_generate_date_header_value() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = call i8* @libewf_header_value_string_alloc(i32 20)
store i8* %4, i8** %1
%5 = call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %6, %struct.tm** %3
%7 = load i8*, i8** %1
%8 = load %struct.tm*, %struct.tm** %3
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1900
%12 = load %struct.tm*, %struct.tm** %3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = load %struct.tm*, %struct.tm** %3
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = load %struct.tm*, %struct.tm** %3
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 3
%21 = load i32, i32* %20
%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 5
%27 = load i32, i32* %26
%28 = call i32 @snprintf(i8* %7, i32 20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %15, i32 %18, i32 %21, i32 %24, i32 %27)
%29 = load i8*, i8** %1
ret i8* %29
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"%4d %d %d %d %d %d\00"
define i8* @libewf_generate_date_header_value() {
%1 = alloca i32
%2 = tail call i8* @libewf_header_value_string_alloc(i32 20)
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %1
%5 = call %struct.tm* @localtime(i32* %1)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = add nsw i32 %7, 1900
%9 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %2, i32 20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19)
ret i8* %2
}