#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*/ _DEBUG(int, char *, int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
struct tm *getLocalTime(time_t *when) {
  struct tm *mytime;
  int free_when = 0;
  if (when == NULL) {
    when = malloc(sizeof(time_t));
    *when = time((time_t *)NULL);
    free_when = 1;
  }
  mytime = (struct tm *)malloc(sizeof(struct tm));
  localtime_r(when, mytime);
  if (mytime == NULL) {
    _DEBUG(29,
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/mcoulont/cpige_month/refs/heads/master/"
           "mytime.c",
           1, "Memory allocation failed.");
    exit(1);
  }
  if (free_when)
    free(when);
  return mytime;
}


x86 assembly (clang, -O0):
<getLocalTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <getLocalTime+0x44>
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x14(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <localtime_r@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11f1 <getLocalTime+0x91>
mov    $0x1d,%edi
lea    0xe2a(%rip),%rsi
mov    $0x1,%edx
lea    0xea8(%rip),%rcx
call   1070 <_DEBUG@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     1204 <getLocalTime+0xa4>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLocalTime>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    %rdi,%r14
test   %rdi,%rdi
jne    1187 <getLocalTime+0x27>
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,(%r14)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <localtime_r@plt>
test   %rbx,%rbx
je     11ba <getLocalTime+0x5a>
test   %r15,%r15
jne    11b1 <getLocalTime+0x51>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3f(%rip),%rsi
lea    0xec2(%rip),%rcx
mov    $0x1d,%edi
mov    $0x1,%edx
call   1070 <_DEBUG@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mcoulont/cpige_month/refs/heads/master/mytime.c\00"
@.str.1 = [26 x i8] c"Memory allocation failed.\00"
define %struct.tm* @getLocalTime(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.tm*
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32* @malloc(i32 4)
store i32* %8, i32** %2
%9 = call i32 @time(i32* null)
%10 = load i32*, i32** %2
store i32 %9, i32* %10
store i32 1, i32* %4
br label %11
11: ; preds = %7, %1
%12 = call i32* @malloc(i32 4)
%13 = bitcast i32* %12 to %struct.tm*
store %struct.tm* %13, %struct.tm** %3
%14 = load i32*, i32** %2
%15 = load %struct.tm*, %struct.tm** %3
%16 = call i32 @localtime_r(i32* %14, %struct.tm* %15)
%17 = load %struct.tm*, %struct.tm** %3
%18 = icmp eq %struct.tm* %17, null
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = call i32 @_DEBUG(i32 29, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32*, i32** %2
%27 = call i32 @free(i32* %26)
br label %28
28: ; preds = %25, %22
%29 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %29
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mcoulont/cpige_month/refs/heads/master/mytime.c\00"
@.str.1 = [26 x i8] c"Memory allocation failed.\00"
define %struct.tm* @getLocalTime(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32* @malloc(i32 4)
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %4
br label %6
6: ; preds = %3, %1
%7 = phi i32* [ %4, %3 ], [ %0, %1 ]
%8 = tail call i32* @malloc(i32 4)
%9 = bitcast i32* %8 to %struct.tm*
%10 = tail call i32 @localtime_r(i32* %7, %struct.tm* %9)
%11 = icmp eq i32* %8, null
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = tail call i32 @_DEBUG(i32 29, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %6
br i1 %2, label %16, label %18
16: ; preds = %15
%17 = tail call i32 @free(i32* %7)
br label %18
18: ; preds = %16, %15
ret %struct.tm* %9
}