#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strftime(char *, int, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *format_time(const char *format_string) {
  char *outstr = malloc(sizeof(char) * 512);
  time_t t;
  struct tm *tmp;
  t = time(NULL);
  tmp = localtime(&t);
  if (tmp == NULL) {
    perror("localtime");
    exit(EXIT_FAILURE);
  }
  if (strftime(outstr, 512, format_string, tmp) == 0) {
    fprintf(stderr, "strftime returned 0");
    exit(EXIT_FAILURE);
  }
  return outstr;
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <format_time+0x58>
lea    0xe4b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
call   1070 <strftime@plt>
cmp    $0x0,%rax
jne    120b <format_time+0x9b>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11c1 <format_time+0x51>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
je     11cf <format_time+0x5f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe38(%rip),%rdi
call   1080 <perror@plt>
jmp    11e4 <format_time+0x74>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"strftime returned 0\00"
define i8* @format_time(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 512)
store i8* %6, i8** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %4
%8 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %8, %struct.tm** %5
%9 = load %struct.tm*, %struct.tm** %5
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = load %struct.tm*, %struct.tm** %5
%19 = call i64 @strftime(i8* %16, i32 512, i8* %17, %struct.tm* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"strftime returned 0\00"
define i8* @format_time(i8* %0) {
%2 = alloca i32
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @localtime(i32* %2)
%7 = icmp eq %struct.tm* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = call i64 @strftime(i8* %3, i32 512, i8* %0, %struct.tm* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
ret i8* %3
}