#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 *, char *, char const *, struct tm const *);
char *out_ch(char *, char *, char);
size_t strftime(char *buf, size_t size, const char *format,
                const struct tm *t) {
  char *end = &buf[size];
  char *dest = fmt(buf, end, format, t);
  dest = out_ch(dest, end, '\0');
  return dest ? dest - buf : 0;
}


x86 assembly (clang, -O0):
<strftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <fmt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <out_ch@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     118f <strftime+0x6f>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    119a <strftime+0x7a>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    119a <strftime+0x7a>
mov    -0x38(%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
add    %rdi,%rbx
mov    %rbx,%rsi
call   1030 <fmt@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <out_ch@plt>
mov    %rax,%rcx
sub    %r14,%rcx
test   %rax,%rax
cmovne %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
define i64 @strftime(i8* %0, i64 %1, i8* %2, %struct.tm* %3) {
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = tail call i8* @fmt(i8* %0, i8* %5, i8* %2, %struct.tm* %3)
%7 = tail call i8* @out_ch(i8* %6, i8* %5, i8 signext 0)
%8 = icmp eq i8* %7, null
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = select i1 %8, i64 0, i64 %11
ret i64 %12
}