#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 *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
char *smprintf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unsetenv(char *);
char *mktimes(char *fmt, char *tzname) {
  char buf[129];
  char *tzorig = NULL;
  time_t tim;
  struct tm *timtm;
  memset(buf, 0, sizeof(buf));
  if (tzname) {
    tzorig = getenv("TZ");
    if (tzorig)
      tzorig = smprintf("%s", tzorig);
    setenv("TZ", tzname, 1);
  }
  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);
  }
  if (tzorig) {
    setenv("TZ", tzorig, 1);
    free(tzorig);
  } else {
    unsetenv("TZ");
  }
  return smprintf("%s", buf);
}


x86 assembly (clang, -O0):
<mktimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1080 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     124c <mktimes+0x8c>
lea    0xdfd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     1237 <mktimes+0x77>
mov    -0xa8(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1060 <smprintf@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x1,%edx
call   1070 <setenv@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0xac(%rbp)
lea    -0xac(%rbp),%rdi
call   1050 <localtime@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    1292 <mktimes+0xd2>
lea    0xd83(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xb8(%rbp),%rcx
mov    $0x80,%esi
call   10b0 <strftime@plt>
cmp    $0x0,%eax
jne    12d6 <mktimes+0x116>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0xa8(%rbp)
je     130d <mktimes+0x14d>
mov    -0xa8(%rbp),%rsi
lea    0xd0e(%rip),%rdi
mov    $0x1,%edx
call   1070 <setenv@plt>
mov    -0xa8(%rbp),%rdi
call   1040 <free@plt>
jmp    1319 <mktimes+0x159>
lea    0xcec(%rip),%rdi
call   10d0 <unsetenv@plt>
lea    -0xa0(%rbp),%rsi
lea    0xcdc(%rip),%rdi
call   1060 <smprintf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktimes>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0x81,%edx
call   1080 <memset@plt>
test   %rbx,%rbx
je     1227 <mktimes+0x67>
lea    0xe0e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1210 <mktimes+0x50>
lea    0xe00(%rip),%rdi
mov    %rax,%rsi
call   1060 <smprintf@plt>
mov    %rax,%r15
jmp    1213 <mktimes+0x53>
xor    %r15d,%r15d
lea    0xde6(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <setenv@plt>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <localtime@plt>
test   %rax,%rax
je     12a0 <mktimes+0xe0>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   10b0 <strftime@plt>
test   %eax,%eax
je     12b6 <mktimes+0xf6>
lea    0xd9f(%rip),%rdi
test   %r15,%r15
je     127d <mktimes+0xbd>
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <setenv@plt>
mov    %r15,%rdi
call   1040 <free@plt>
jmp    1282 <mktimes+0xc2>
call   10d0 <unsetenv@plt>
lea    0xd7a(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <smprintf@plt>
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd5f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"localtime\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"strftime == 0\0A\00"
define i8* @mktimes(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [129 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.tm*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %6
%9 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 129)
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i8* %19, i8** %6
br label %20
20: ; preds = %17, %13
%21 = load i8*, i8** %4
%22 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21, i32 1)
br label %23
23: ; preds = %20, %2
%24 = call i32 @time(i32* null)
store i32 %24, i32* %7
%25 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %25, %struct.tm** %8
%26 = load %struct.tm*, %struct.tm** %8
%27 = icmp eq %struct.tm* %26, null
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%33 = load i8*, i8** %3
%34 = load %struct.tm*, %struct.tm** %8
%35 = call i32 @strftime(i8* %32, i32 128, i8* %33, %struct.tm* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %31
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8*, i8** %6
%46 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %45, i32 1)
%47 = load i8*, i8** %6
%48 = call i32 @free(i8* %47)
br label %51
49: ; preds = %41
%50 = call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
%52 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%53 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %52)
ret i8* %53
}

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