#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));
  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>
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    1205 <mktimes+0x75>
lea    0xe0a(%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    1249 <mktimes+0xb9>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xa0(%rbp),%rsi
lea    0xdc2(%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>
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     1208 <mktimes+0x78>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1090 <strftime@plt>
test   %eax,%eax
je     121e <mktimes+0x8e>
lea    0xe26(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <smprintf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdf1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%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 = call i32 @settz(i8* %10)
%12 = call i32 @time(i32* null)
store i32 %12, i32* %6
%13 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %13, %struct.tm** %7
%14 = load %struct.tm*, %struct.tm** %7
%15 = icmp eq %struct.tm* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = load %struct.tm*, %struct.tm** %7
%23 = call i32 @strftime(i8* %20, i32 128, i8* %21, %struct.tm* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%31 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %30)
ret i8* %31
}

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 = call i32 @settz(i8* %1)
%9 = call i32 @time(i32* null)
store i32 %9, i32* %4
%10 = call %struct.tm* @localtime(i32* %4)
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @strftime(i8* %5, i32 128, i8* %0, %struct.tm* %10)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
ret i8* %23
}