#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*/ result;

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ memcpy(struct tm *, struct tm *, int);
struct tm *localtime_r(const time_t *timer, struct tm *result) {
  struct tm *local_result;
  local_result = localtime(timer);
  if (local_result == NULL || result == NULL)
    return NULL;
  memcpy(result, local_result, sizeof(result));
  return result;
}


x86 assembly (clang, -O0):
<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,-0x20(%rbp)
je     1153 <localtime_r+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    1160 <localtime_r+0x40>
movq   $0x0,-0x8(%rbp)
jmp    117a <localtime_r+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<localtime_r>:
push   %rbx
mov    %rsi,%rbx
call   1030 <localtime@plt>
xor    %ecx,%ecx
test   %rbx,%rbx
je     1148 <localtime_r+0x28>
test   %rax,%rax
je     1148 <localtime_r+0x28>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rcx
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define %struct.tm* @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** %6
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load %struct.tm*, %struct.tm** %5
%13 = icmp eq %struct.tm* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store %struct.tm* null, %struct.tm** %3
br label %20
15: ; preds = %11
%16 = load %struct.tm*, %struct.tm** %5
%17 = load %struct.tm*, %struct.tm** %6
%18 = call i32 @memcpy(%struct.tm* %16, %struct.tm* %17, i32 8)
%19 = load %struct.tm*, %struct.tm** %5
store %struct.tm* %19, %struct.tm** %3
br label %20
20: ; preds = %15, %14
%21 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %21
}

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