#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 scalar_t__ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ checkstr(char *, char const *);
struct tm *gmtime_r(scalar_t__ *, struct tm *);
struct tm *localtime_r(scalar_t__ *, struct tm *);
scalar_t__ mktime(struct tm *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
void testtime(time_t t, const char *fmt, const char *expect, int local) {
  struct tm tm;
  struct tm *tmp;
  char buf[128];
  time_t t2;
  if (local)
    tmp = localtime_r(&t, &tm);
  else
    tmp = gmtime_r(&t, &tm);
  assert(tmp == &tm);
  strftime(buf, sizeof(buf), fmt, tmp);
  checkstr(buf, expect);
  if (local) {
    t2 = mktime(&tm);
    assert(t2 == t);
  }
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<testtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11aa <testtime+0x3a>
lea    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    %rax,-0x28(%rbp)
jmp    11bb <testtime+0x4b>
lea    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gmtime_r@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rax
cmp    %rax,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x80,%esi
call   1090 <strftime@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <checkstr@plt>
cmpl   $0x0,-0x1c(%rbp)
je     122b <testtime+0xbb>
lea    -0x20(%rbp),%rdi
call   1080 <mktime@plt>
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
cmp    -0x8(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0xb0(%rbp),%rsi
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testtime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
test   %ecx,%ecx
je     11a0 <testtime+0x30>
call   1030 <localtime_r@plt>
jmp    11a5 <testtime+0x35>
call   1050 <gmtime_r@plt>
mov    %rax,%rbx
mov    %rsp,%rax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1070 <assert@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1090 <strftime@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <checkstr@plt>
test   %r12d,%r12d
je     11f9 <testtime+0x89>
mov    %rsp,%rdi
call   1080 <mktime@plt>
xor    %edi,%edi
cmp    0x8(%rsp),%rax
sete   %dil
call   1070 <assert@plt>
lea    0xe00(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
define void @testtime(i64 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.tm
%10 = alloca %struct.tm*
%11 = alloca [128 x i8]
%12 = alloca i64
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call %struct.tm* @localtime_r(i64* %5, %struct.tm* %9)
store %struct.tm* %16, %struct.tm** %10
br label %19
17: ; preds = %4
%18 = call %struct.tm* @gmtime_r(i64* %5, %struct.tm* %9)
store %struct.tm* %18, %struct.tm** %10
br label %19
19: ; preds = %17, %15
%20 = load %struct.tm*, %struct.tm** %10
%21 = icmp eq %struct.tm* %20, %9
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = load %struct.tm*, %struct.tm** %10
%27 = call i32 @strftime(i8* %24, i32 128, i8* %25, %struct.tm* %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%29 = load i8*, i8** %7
%30 = call i32 @checkstr(i8* %28, i8* %29)
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %19
%34 = call i64 @mktime(%struct.tm* %9)
store i64 %34, i64* %12
%35 = load i64, i64* %12
%36 = load i64, i64* %5
%37 = icmp eq i64 %35, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
br label %40
40: ; preds = %33, %19
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %41)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
define void @testtime(i64 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca %struct.tm
%7 = alloca [128 x i8]
store i64 %0, i64* %5
%8 = bitcast %struct.tm* %6 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%10 = icmp eq i32 %3, 0
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = call %struct.tm* @localtime_r(i64* %5, %struct.tm* %6)
br label %15
13: ; preds = %4
%14 = call %struct.tm* @gmtime_r(i64* %5, %struct.tm* %6)
br label %15
15: ; preds = %13, %11
%16 = phi %struct.tm* [ %12, %11 ], [ %14, %13 ]
%17 = icmp eq %struct.tm* %16, %6
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @strftime(i8* %9, i32 128, i8* %1, %struct.tm* %16)
%21 = call i32 @checkstr(i8* %9, i8* %2)
br i1 %10, label %28, label %22
22: ; preds = %15
%23 = call i64 @mktime(%struct.tm* %6)
%24 = load i64, i64* %5
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
br label %28
28: ; preds = %22, %15
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
ret void
}