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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(int /*<<< orphan*/ *);
char *smprintf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *mktimes(char *fmt) {
  char buf[129];
  time_t tim;
  struct tm *timtm;
  tim = time(NULL);
  timtm = localtime(&tim);
  if (timtm == NULL)
    return smprintf("");
  if (!strftime(buf, sizeof(buf) - 1, fmt, timtm)) {
    fprintf(stderr, "strftime == 0\n");
    return smprintf("");
  }
  return smprintf("%s", buf);
}


x86 assembly (clang, -O0):
<mktimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    11a6 <mktimes+0x56>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    1210 <mktimes+0xc0>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    $0x80,%esi
call   1070 <strftime@plt>
cmp    $0x0,%eax
jne    11f7 <mktimes+0xa7>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    1210 <mktimes+0xc0>
lea    -0xa0(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktimes>:
push   %rbx
sub    $0xa0,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11b8 <mktimes+0x68>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %eax,%eax
je     11a3 <mktimes+0x53>
lea    0xe7a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <smprintf@plt>
jmp    11c6 <mktimes+0x76>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1040 <smprintf@plt>
add    $0xa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [15 x i8] c"strftime == 0\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i8* @mktimes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [129 x i8]
%5 = alloca i32
%6 = alloca %struct.tm*
store i8* %0, i8** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %5
%8 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %8, %struct.tm** %6
%9 = load %struct.tm*, %struct.tm** %6
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %2
br label %26
13: ; preds = %1
%14 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = load %struct.tm*, %struct.tm** %6
%17 = call i32 @strftime(i8* %14, i32 128, i8* %15, %struct.tm* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%22 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %2
br label %26
23: ; preds = %13
%24 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 0
%25 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i8* %25, i8** %2
br label %26
26: ; preds = %23, %19, %11
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [15 x i8] c"strftime == 0\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i8* @mktimes(i8* %0) {
%2 = alloca [129 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @localtime(i32* %3)
%8 = icmp eq %struct.tm* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
11: ; preds = %1
%12 = call i32 @strftime(i8* %4, i32 128, i8* %0, %struct.tm* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %11
%19 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %20
20: ; preds = %18, %14, %9
%21 = phi i8* [ %10, %9 ], [ %19, %18 ], [ %17, %14 ]
ret i8* %21
}