#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*/ fatal(char *);
struct tm *localtime(int /*<<< orphan*/ *);
size_t strftime(char *, int, char *, struct tm *);
char *mktimes(char *fmt, time_t tim) {
  static char buf[128];
  struct tm *timtm;
  size_t n;
  if (!(timtm = localtime(&tim)))
    fatal("localtime\n");
  if (!(n = strftime(buf, sizeof(buf) - 1, fmt, timtm)))
    fatal("strftime == 0\n");
  buf[n] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<mktimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1162 <mktimes+0x32>
lea    0xea3(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0x2edf(%rip),%rdi
mov    $0x7f,%esi
call   1040 <strftime@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1195 <mktimes+0x65>
lea    0xe7b(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rcx
lea    0x2eb0(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea5(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktimes>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115e <mktimes+0x2e>
lea    0xea7(%rip),%rdi
call   1050 <fatal@plt>
lea    0x2eeb(%rip),%r15
mov    %r15,%rdi
mov    $0x7f,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <strftime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118c <mktimes+0x5c>
lea    0xe84(%rip),%rdi
call   1050 <fatal@plt>
movb   $0x0,(%rbx,%r15,1)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@mktimes.buf = internal global [128 x i8] zeroinitializer
@.str = [11 x i8] c"localtime\0A\00"
@.str.1 = [15 x i8] c"strftime == 0\0A\00"
define i8* @mktimes(i8* %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = call %struct.tm* @localtime(i32* %3)
%5 = icmp eq %struct.tm* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @fatal(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = call i64 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mktimes.buf, i64 0, i64 0), i32 127, i8* %0, %struct.tm* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* @mktimes.buf, i64 0, i64 %9
store i8 0, i8* %14
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mktimes.buf, i64 0, i64 0)
}