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

/* Variables and functions */
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
scalar_t__ strftime(char *, int, char *, struct tm *);
char *strptime(char *, char *, struct tm *);
char *convert_date(char *result, char *data, char *from, char *to, int size) {
  struct tm tm;
  memset(&tm, 0, sizeof(tm));
  char *end = strptime(data, from, &tm);
  if (end == NULL || *end != '\0')
    return NULL;
  if (strftime(result, size, to, &tm) <= 0)
    return NULL;
  return result;
}


x86 assembly (clang, -O0):
<convert_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strptime@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     118c <convert_date+0x5c>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1199 <convert_date+0x69>
movq   $0x0,-0x8(%rbp)
jmp    11cc <convert_date+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <strftime@plt>
cmp    $0x0,%rax
jg     11c4 <convert_date+0x94>
movq   $0x0,-0x8(%rbp)
jmp    11cc <convert_date+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_date>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <strptime@plt>
test   %rax,%rax
je     119f <convert_date+0x6f>
cmpb   $0x0,(%rax)
je     1181 <convert_date+0x51>
xor    %ebx,%ebx
jmp    119f <convert_date+0x6f>
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %r12d,%esi
mov    0x10(%rsp),%rdx
call   1040 <strftime@plt>
xor    %ebx,%ebx
test   %rax,%rax
cmovg  %r14,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define i8* @convert_date(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.tm
%13 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = call i32 @memset(%struct.tm* %12, i32 0, i32 4)
%15 = load i8*, i8** %8
%16 = load i8*, i8** %9
%17 = call i8* @strptime(i8* %15, i8* %16, %struct.tm* %12)
store i8* %17, i8** %13
%18 = load i8*, i8** %13
%19 = icmp eq i8* %18, null
br i1 %19, label %25, label %20
20: ; preds = %5
%21 = load i8*, i8** %13
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20, %5
store i8* null, i8** %6
br label %35
26: ; preds = %20
%27 = load i8*, i8** %7
%28 = load i32, i32* %11
%29 = load i8*, i8** %10
%30 = call i64 @strftime(i8* %27, i32 %28, i8* %29, %struct.tm* %12)
%31 = icmp sle i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i8* null, i8** %6
br label %35
33: ; preds = %26
%34 = load i8*, i8** %7
store i8* %34, i8** %6
br label %35
35: ; preds = %33, %32, %25
%36 = load i8*, i8** %6
ret i8* %36
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define i8* @convert_date(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca %struct.tm
%7 = bitcast %struct.tm* %6 to i8*
%8 = call i32 @memset(%struct.tm* %6, i32 0, i32 4)
%9 = call i8* @strptime(i8* %1, i8* %2, %struct.tm* %6)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i64 @strftime(i8* %0, i32 %4, i8* %3, %struct.tm* %6)
%16 = icmp slt i64 %15, 1
%17 = select i1 %16, i8* null, i8* %0
br label %18
18: ; preds = %14, %5, %11
%19 = phi i8* [ null, %11 ], [ null, %5 ], [ %17, %14 ]
ret i8* %19
}