#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 uint8_t;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atoll(char *);
int /*<<< orphan*/ free(char *);
char *libewf_header_value_string_alloc(int);
struct tm *localtime(int /*<<< orphan*/ *);
size_t strftime(char *, int, char *, struct tm *);
char *libewf_convert_date_header2_value(char *header_value,
                                        uint8_t date_format) {
  char *date_string;
  time_t timestamp;
  struct tm *time_elements;
  size_t result = 0;
  if (header_value == NULL) {
    return (NULL);
  }
  date_string = libewf_header_value_string_alloc(20);
  timestamp = atoll(header_value);
  time_elements = localtime(&timestamp);
  if (date_format == 0x02) {
    result = strftime(date_string, 20, "%m/%d/%Y %H:%M:%S", time_elements);
  } else if (date_format == 0x01) {
    result = strftime(date_string, 20, "%d/%m/%Y %H:%M:%S", time_elements);
  }
  if (result == 0) {
    free(date_string);
    return (NULL);
  }
  return (date_string);
}


x86 assembly (clang, -O0):
<libewf_convert_date_header2_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <libewf_convert_date_header2_value+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1227 <libewf_convert_date_header2_value+0xd7>
mov    $0x14,%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <atoll@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11d2 <libewf_convert_date_header2_value+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x14,%esi
lea    0xe3c(%rip),%rdx
call   1070 <strftime@plt>
mov    %rax,-0x38(%rbp)
jmp    11fe <libewf_convert_date_header2_value+0xae>
cmpl   $0x1,-0x14(%rbp)
jne    11f9 <libewf_convert_date_header2_value+0xa9>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x14,%esi
lea    0xe22(%rip),%rdx
call   1070 <strftime@plt>
mov    %rax,-0x38(%rbp)
jmp    11fe <libewf_convert_date_header2_value+0xae>
cmpq   $0x0,-0x38(%rbp)
jne    121f <libewf_convert_date_header2_value+0xcf>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1227 <libewf_convert_date_header2_value+0xd7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libewf_convert_date_header2_value>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11bf <libewf_convert_date_header2_value+0x6f>
mov    %esi,%r14d
mov    %rdi,%rbp
mov    $0x14,%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1060 <atoll@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
cmp    $0x2,%r14d
je     119b <libewf_convert_date_header2_value+0x4b>
cmp    $0x1,%r14d
jne    11b7 <libewf_convert_date_header2_value+0x67>
lea    0xe79(%rip),%rdx
jmp    11a2 <libewf_convert_date_header2_value+0x52>
lea    0xe5e(%rip),%rdx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
jne    11c1 <libewf_convert_date_header2_value+0x71>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%m/%d/%Y %H:%M:%S\00"
@.str.1 = [18 x i8] c"%d/%m/%Y %H:%M:%S\00"
define i8* @libewf_convert_date_header2_value(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 0, i64* %9
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %40
13: ; preds = %2
%14 = call i8* @libewf_header_value_string_alloc(i32 20)
store i8* %14, i8** %6
%15 = load i8*, i8** %4
%16 = call i32 @atoll(i8* %15)
store i32 %16, i32* %7
%17 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %17, %struct.tm** %8
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = load %struct.tm*, %struct.tm** %8
%23 = call i64 @strftime(i8* %21, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %22)
store i64 %23, i64* %9
br label %32
24: ; preds = %13
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8*, i8** %6
%29 = load %struct.tm*, %struct.tm** %8
%30 = call i64 @strftime(i8* %28, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %29)
store i64 %30, i64* %9
br label %31
31: ; preds = %27, %24
br label %32
32: ; preds = %31, %20
%33 = load i64, i64* %9
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
store i8* null, i8** %3
br label %40
38: ; preds = %32
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %35, %12
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%m/%d/%Y %H:%M:%S\00"
@.str.1 = [18 x i8] c"%d/%m/%Y %H:%M:%S\00"
define i8* @libewf_convert_date_header2_value(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call i8* @libewf_header_value_string_alloc(i32 20)
%8 = tail call i32 @atoll(i8* %0)
store i32 %8, i32* %3
%9 = call %struct.tm* @localtime(i32* %3)
switch i32 %1, label %15 [
i32 2, label %11
i32 1, label %10
]
10: ; preds = %6
br label %11
11: ; preds = %6, %10
%12 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %6 ]
%13 = call i64 @strftime(i8* %7, i32 20, i8* %12, %struct.tm* %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6, %11
%16 = call i32 @free(i8* %7)
br label %17
17: ; preds = %11, %2, %15
%18 = phi i8* [ null, %15 ], [ null, %2 ], [ %7, %11 ]
ret i8* %18
}