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

/* Variables and functions */
size_t strftime(char *, int, char const *, struct tm *);
char *my_strftime(const char *format, struct tm *tmp) {
  static char buf[1000];
  size_t s;
  if (tmp == NULL) {
    return NULL;
  }
  s = strftime(buf, 1000,
               (format != NULL) ? format : "%A %B %d %I:%M:%S %p %Y %Z", tmp);
  return (s == 0) ? NULL : buf;
}


x86 assembly (clang, -O0):
<my_strftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1138 <my_strftime+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1196 <my_strftime+0x86>
cmpq   $0x0,-0x10(%rbp)
je     1150 <my_strftime+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <my_strftime+0x50>
lea    0xea9(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <my_strftime+0x50>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0x2ed1(%rip),%rdi
mov    $0x3e8,%esi
call   1030 <strftime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    0x2eb8(%rip),%rax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strftime>:
push   %rbx
test   %rsi,%rsi
je     1144 <my_strftime+0x34>
mov    %rsi,%rcx
test   %rdi,%rdi
lea    0xedd(%rip),%rdx
cmovne %rdi,%rdx
lea    0x2f12(%rip),%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <strftime@plt>
test   %rax,%rax
cmove  %rax,%rbx
jmp    1146 <my_strftime+0x36>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@my_strftime.buf = internal global [1000 x i8] zeroinitializer
@.str = [27 x i8] c"%A %B %d %I:%M:%S %p %Y %Z\00"
define i8* @my_strftime(i8* %0, %struct.tm* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i64
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load %struct.tm*, %struct.tm** %5
%8 = icmp eq %struct.tm* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %24
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i8*, i8** %4
br label %16
15: ; preds = %10
br label %16
16: ; preds = %15, %13
%17 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %15 ]
%18 = load %struct.tm*, %struct.tm** %5
%19 = call i64 @strftime(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @my_strftime.buf, i64 0, i64 0), i32 1000, i8* %17, %struct.tm* %18)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* null, i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @my_strftime.buf, i64 0, i64 0)
store i8* %23, i8** %3
br label %24
24: ; preds = %16, %9
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@my_strftime.buf = internal global [1000 x i8] zeroinitializer
@.str = [27 x i8] c"%A %B %d %I:%M:%S %p %Y %Z\00"
define i8* @my_strftime(i8* %0, %struct.tm* %1) {
%3 = icmp eq %struct.tm* %1, null
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp eq i8* %0, null
%6 = select i1 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0
%7 = tail call i64 @strftime(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @my_strftime.buf, i64 0, i64 0), i32 1000, i8* %6, %struct.tm* %1)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8* null, i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @my_strftime.buf, i64 0, i64 0)
br label %10
10: ; preds = %2, %4
%11 = phi i8* [ %9, %4 ], [ null, %2 ]
ret i8* %11
}