#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 */
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*/ 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("mktimes: localtime returned null");
  }
  if (!strftime(buf, sizeof(buf) - 1, fmt, timtm)) {
    perror("strftime == 0");
  }
  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   1070 <time@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    11db <mktimes+0x6b>
lea    0xe2a(%rip),%rdi
call   1090 <perror@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    $0x80,%esi
call   1080 <strftime@plt>
cmp    $0x0,%eax
jne    120c <mktimes+0x9c>
lea    0xe1a(%rip),%rdi
call   1090 <perror@plt>
lea    -0xa0(%rbp),%rsi
lea    0xe15(%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   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11eb <mktimes+0x7b>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1080 <strftime@plt>
test   %eax,%eax
je     11f9 <mktimes+0x89>
lea    0xe59(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <smprintf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0e(%rip),%rdi
call   1090 <perror@plt>
jmp    11b6 <mktimes+0x46>
lea    0xe21(%rip),%rdi
call   1090 <perror@plt>
jmp    11cf <mktimes+0x5f>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [33 x i8] c"mktimes: localtime returned null\00"
@.str.1 = [14 x i8] c"strftime == 0\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 %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = load %struct.tm*, %struct.tm** %7
%22 = call i32 @strftime(i8* %19, i32 128, i8* %20, %struct.tm* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
%27 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%28 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %27)
ret i8* %28
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [33 x i8] c"mktimes: localtime returned null\00"
@.str.1 = [14 x i8] c"strftime == 0\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 %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 @strftime(i8* %5, i32 128, i8* %0, %struct.tm* %10)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
ret i8* %20
}