#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ settz(char *);
char *smprintf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *mktimes(char *fmt, char *tzname) {
  char buf[129];
  time_t tim;
  struct tm *timtm;
  memset(buf, 0, sizeof(buf));
  if (tzname != NULL) {
    settz(tzname);
  }
  tim = time(NULL);
  timtm = localtime(&tim);
  if (timtm == NULL) {
    perror("localtime");
    exit(1);
  }
  if (!strftime(buf, sizeof(buf) - 1, fmt, timtm)) {
    fprintf(stderr, "strftime == 0\n");
    exit(1);
  }
  return smprintf("%s", buf);
}


x86 assembly (clang, -O0):
<mktimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ca <mktimes+0x3a>
mov    -0x10(%rbp),%rdi
call   1050 <settz@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    1210 <mktimes+0x80>
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    $0x80,%esi
call   1090 <strftime@plt>
cmp    $0x0,%eax
jne    1254 <mktimes+0xc4>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xa0(%rbp),%rsi
lea    0xdb7(%rip),%rdi
call   1040 <smprintf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktimes>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1060 <memset@plt>
test   %rbx,%rbx
je     11be <mktimes+0x2e>
mov    %rbx,%rdi
call   1050 <settz@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     120d <mktimes+0x7d>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1090 <strftime@plt>
test   %eax,%eax
je     1223 <mktimes+0x93>
lea    0xe21(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <smprintf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdec(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@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, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [129 x i8]
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 129)
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @settz(i8* %13)
br label %15
15: ; preds = %12, %2
%16 = call i32 @time(i32* null)
store i32 %16, i32* %6
%17 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %17, %struct.tm** %7
%18 = load %struct.tm*, %struct.tm** %7
%19 = icmp eq %struct.tm* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = load %struct.tm*, %struct.tm** %7
%27 = call i32 @strftime(i8* %24, i32 128, i8* %25, %struct.tm* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%35 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %34)
ret i8* %35
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@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, i8* %1) {
%3 = alloca [129 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i32 @memset(i8* %5, i32 0, i32 129)
%8 = icmp eq i8* %1, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @settz(i8* %1)
br label %11
11: ; preds = %9, %2
%12 = call i32 @time(i32* null)
store i32 %12, i32* %4
%13 = call %struct.tm* @localtime(i32* %4)
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = call i32 @strftime(i8* %5, i32 128, i8* %0, %struct.tm* %13)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
ret i8* %26
}