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

/* Variables and functions */
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int strlen(char *);
int /*<<< orphan*/ strptime(char *, char *, struct tm *);
time_t *mkTimestamp(char *timeval) {
  char buf[255];
  struct tm tm;
  time_t *timestamp = malloc(sizeof(timestamp));
  tm.tm_isdst = (timeval[strlen(timeval) - 1] == 'W') ? 0 : 1;
  strptime(timeval, "%y%m%d%H%M%S", &tm);
  *timestamp = mktime(&tm);
  strftime(buf, sizeof(buf), "%d %b %Y %H:%M:%S", &tm);
  return timestamp;
}


x86 assembly (clang, -O0):
<mkTimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x57,%edx
cmove  %ecx,%eax
mov    %eax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x118(%rbp),%rdx
call   1070 <strptime@plt>
lea    -0x118(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,%ecx
mov    -0x120(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
lea    0xe22(%rip),%rdx
lea    -0x118(%rbp),%rcx
call   1060 <strftime@plt>
mov    -0x120(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkTimestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0x57,-0x1(%rax,%rbx,1)
setne  %cl
mov    %ecx,0x8(%rsp)
lea    0xe75(%rip),%rsi
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rdx
call   1070 <strptime@plt>
mov    %r15,%rdi
call   1050 <mktime@plt>
mov    %eax,(%r14)
lea    0xe60(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
mov    %r15,%rcx
call   1060 <strftime@plt>
mov    %r14,%rax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [13 x i8] c"%y%m%d%H%M%S\00"
@.str.1 = [18 x i8] c"%d %b %Y %H:%M:%S\00"
define i32* @mkTimestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca [255 x i8]
%4 = alloca %struct.tm
%5 = alloca i32*
store i8* %0, i8** %2
%6 = call i32* @malloc(i32 8)
store i32* %6, i32** %5
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 87
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 0, i32 1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i8*, i8** %2
%20 = call i32 @strptime(i8* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%21 = call i32 @mktime(%struct.tm* %4)
%22 = load i32*, i32** %5
store i32 %21, i32* %22
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%24 = call i32 @strftime(i8* %23, i32 255, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %4)
%25 = load i32*, i32** %5
ret i32* %25
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [13 x i8] c"%y%m%d%H%M%S\00"
@.str.1 = [18 x i8] c"%d %b %Y %H:%M:%S\00"
define noalias i32* @mkTimestamp(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca %struct.tm
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.tm* %3 to i8*
%6 = tail call i32* @malloc(i32 8)
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 87
%13 = zext i1 %12 to i32
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = call i32 @strptime(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.tm* %3)
%16 = call i32 @mktime(%struct.tm* %3)
store i32 %16, i32* %6
%17 = call i32 @strftime(i8* %4, i32 255, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
ret i32* %6
}