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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strdt2tmt(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *format_dt(char *dt, time_t *time_out, struct tm **dtm) {
  char yyyy[5];
  char mm[3];
  char dd[3];
  char *s;
  time_t tm_t;
  strncpy(yyyy, dt, 4);
  yyyy[4] = '\0';
  mm[0] = *(dt + 5);
  mm[1] = *(dt + 6);
  mm[2] = '\0';
  dd[0] = *(dt + 8);
  dd[1] = *(dt + 9);
  dd[2] = '\0';
  tm_t = strdt2tmt(yyyy, mm, dd, "1", "0", "0");
  *dtm = localtime(&tm_t);
  s = (char *)malloc(12);
  strftime(s, 12, "%d-%b-%Y", *dtm);
  *time_out = tm_t;
  return s;
}


x86 assembly (clang, -O0):
<format_dt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x6(%rax),%al
mov    %al,-0x1f(%rbp)
movb   $0x0,-0x1e(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%al
mov    %al,-0x23(%rbp)
mov    -0x8(%rbp),%rax
mov    0x9(%rax),%al
mov    %al,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x1d(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x23(%rbp),%rdx
lea    0xe43(%rip),%rcx
lea    0xe3e(%rip),%r9
mov    %r9,%r8
call   1050 <strdt2tmt@plt>
mov    %eax,-0x34(%rbp)
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    $0xc,%esi
lea    0xdfd(%rip),%rdx
call   1070 <strftime@plt>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_dt>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x13(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x17(%rsp)
mov    0x5(%rbx),%al
mov    %al,0x9(%rsp)
mov    0x6(%rbx),%al
mov    %al,0xa(%rsp)
movb   $0x0,0xb(%rsp)
mov    0x8(%rbx),%al
mov    %al,0x6(%rsp)
mov    0x9(%rbx),%al
mov    %al,0x7(%rsp)
movb   $0x0,0x8(%rsp)
lea    0xe55(%rip),%rcx
lea    0xe50(%rip),%r8
lea    0x9(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    %r12,%rdi
mov    %r8,%r9
call   1050 <strdt2tmt@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,(%r15)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%rcx
lea    0xe15(%rip),%rdx
mov    %rax,%rdi
mov    $0xc,%esi
call   1070 <strftime@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [9 x i8] c"%d-%b-%Y\00"
define i8* @format_dt(i8* %0, i32* %1, %struct.tm** %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.tm**
%7 = alloca [5 x i8]
%8 = alloca [3 x i8]
%9 = alloca [3 x i8]
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store %struct.tm** %2, %struct.tm*** %6
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 4)
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 5
%18 = load i8, i8* %17
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %18, i8* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 6
%22 = load i8, i8* %21
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %22, i8* %23
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 8
%27 = load i8, i8* %26
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %27, i8* %28
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 9
%31 = load i8, i8* %30
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %31, i8* %32
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 2
store i8 0, i8* %33
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%37 = call i32 @strdt2tmt(i8* %34, i8* %35, i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %37, i32* %11
%38 = call %struct.tm* @localtime(i32* %11)
%39 = load %struct.tm**, %struct.tm*** %6
store %struct.tm* %38, %struct.tm** %39
%40 = call i64 @malloc(i32 12)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = load %struct.tm**, %struct.tm*** %6
%44 = load %struct.tm*, %struct.tm** %43
%45 = call i32 @strftime(i8* %42, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %44)
%46 = load i32, i32* %11
%47 = load i32*, i32** %5
store i32 %46, i32* %47
%48 = load i8*, i8** %10
ret i8* %48
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [9 x i8] c"%d-%b-%Y\00"
define i8* @format_dt(i8* %0, i32* nocapture writeonly %1, %struct.tm** nocapture %2) {
%4 = alloca [5 x i8]
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%11 = bitcast i32* %7 to i8*
%12 = call i32 @strncpy(i8* %8, i8* %0, i32 4)
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %0, i64 5
%15 = load i8, i8* %14
store i8 %15, i8* %9
%16 = getelementptr inbounds i8, i8* %0, i64 6
%17 = load i8, i8* %16
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %17, i8* %18
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %0, i64 8
%21 = load i8, i8* %20
store i8 %21, i8* %10
%22 = getelementptr inbounds i8, i8* %0, i64 9
%23 = load i8, i8* %22
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %23, i8* %24
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 0, i8* %25
%26 = call i32 @strdt2tmt(i8* %8, i8* %9, i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %26, i32* %7
%27 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %27, %struct.tm** %2
%28 = call i64 @malloc(i32 12)
%29 = inttoptr i64 %28 to i8*
%30 = load %struct.tm*, %struct.tm** %2
%31 = call i32 @strftime(i8* %29, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %30)
%32 = load i32, i32* %7
store i32 %32, i32* %1
ret i8* %29
}