#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 */
char *_fmt(char *, struct tm const *, char *, char *);
size_t strftime(char *s, size_t maxsize, const char *format,
                const struct tm *t) {
  char *p;
  p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize);
  if (p == s + maxsize)
    return 0;
  *p = '\0';
  return p - s;
}


x86 assembly (clang, -O0):
<strftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1143 <strftime+0x33>
lea    0xec6(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    114b <strftime+0x3b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
call   1030 <_fmt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jne    118a <strftime+0x7a>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <strftime+0x90>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strftime>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdx,%rdx
lea    0xedc(%rip),%rdi
cmovne %rdx,%rdi
add    %r14,%rbx
mov    %rcx,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <_fmt@plt>
cmp    %rbx,%rax
je     1146 <strftime+0x36>
movb   $0x0,(%rax)
sub    %r14,%rax
jmp    1148 <strftime+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%c\00"
define i64 @strftime(i8* %0, i64 %1, i8* %2, %struct.tm* %3) {
%5 = icmp eq i8* %2, null
%6 = select i1 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2
%7 = getelementptr inbounds i8, i8* %0, i64 %1
%8 = tail call i8* @_fmt(i8* %6, %struct.tm* %3, i8* %0, i8* %7)
%9 = icmp eq i8* %8, %7
br i1 %9, label %14, label %10
10: ; preds = %4
store i8 0, i8* %8
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
br label %14
14: ; preds = %4, %10
%15 = phi i64 [ %13, %10 ], [ 0, %4 ]
ret i64 %15
}