#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;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ memcpy(struct tm *, struct tm const *, int);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
struct tm *fake_localtime_r(const time_t *time, struct tm *result) {
  const struct tm *static_result = localtime(time);
  assert(result != NULL);
  if (static_result == NULL) {
    memset(result, 0, sizeof(*result));
    return NULL;
  } else {
    memcpy(result, static_result, sizeof(*result));
    return result;
  }
}


x86 assembly (clang, -O0):
<fake_localtime_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1197 <fake_localtime_r+0x57>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <fake_localtime_r+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fake_localtime_r>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1030 <localtime@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
test   %r14,%r14
je     1174 <fake_localtime_r+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
jmp    1185 <fake_localtime_r+0x45>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define %struct.tm* @fake_localtime_r(i32* %0, %struct.tm* %1) {
%3 = alloca %struct.tm*
%4 = alloca i32*
%5 = alloca %struct.tm*
%6 = alloca %struct.tm*
store i32* %0, i32** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load i32*, i32** %4
%8 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %8, %struct.tm** %6
%9 = load %struct.tm*, %struct.tm** %5
%10 = icmp ne %struct.tm* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load %struct.tm*, %struct.tm** %6
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load %struct.tm*, %struct.tm** %5
%17 = call i32 @memset(%struct.tm* %16, i32 0, i32 4)
store %struct.tm* null, %struct.tm** %3
br label %23
18: ; preds = %2
%19 = load %struct.tm*, %struct.tm** %5
%20 = load %struct.tm*, %struct.tm** %6
%21 = call i32 @memcpy(%struct.tm* %19, %struct.tm* %20, i32 4)
%22 = load %struct.tm*, %struct.tm** %5
store %struct.tm* %22, %struct.tm** %3
br label %23
23: ; preds = %18, %15
%24 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %24
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define %struct.tm* @fake_localtime_r(i32* %0, %struct.tm* %1) {
%3 = tail call %struct.tm* @localtime(i32* %0)
%4 = icmp ne %struct.tm* %1, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq %struct.tm* %3, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @memset(%struct.tm* %1, i32 0, i32 4)
br label %12
10: ; preds = %2
%11 = tail call i32 @memcpy(%struct.tm* %1, %struct.tm* %3, i32 4)
br label %12
12: ; preds = %10, %8
%13 = phi %struct.tm* [ null, %8 ], [ %1, %10 ]
ret %struct.tm* %13
}