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

/* Variables and functions */
char *ctime(scalar_t__ *);
char *strchr(char *, char);
scalar_t__ time(int /*<<< orphan*/ *);
char *get_time_formatted() {
  char *time_string;
  time_t t = time(NULL);
  if (t < 0)
    time_string = "<time read error>";
  else {
    time_string = ctime(&t);
    if (!time_string)
      time_string = "<time format error>";
    else {
      char *newline = strchr(time_string, '\n');
      if (newline)
        newline[0] = 0;
    }
  }
  return time_string;
}


x86 assembly (clang, -O0):
<get_time_formatted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1160 <get_time_formatted+0x30>
lea    0xea9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <get_time_formatted+0x86>
lea    -0x10(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1188 <get_time_formatted+0x58>
lea    0xe93(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <get_time_formatted+0x81>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ac <get_time_formatted+0x7c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b1 <get_time_formatted+0x81>
jmp    11b6 <get_time_formatted+0x86>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_formatted>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
js     116f <get_time_formatted+0x3f>
lea    0x8(%rsp),%rdi
call   1030 <ctime@plt>
test   %rax,%rax
je     1178 <get_time_formatted+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117f <get_time_formatted+0x4f>
movb   $0x0,(%rax)
jmp    117f <get_time_formatted+0x4f>
lea    0xe8a(%rip),%rbx
jmp    117f <get_time_formatted+0x4f>
lea    0xe93(%rip),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"<time read error>\00"
@.str.1 = [20 x i8] c"<time format error>\00"
define i8* @get_time_formatted() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = call i64 @time(i32* null)
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %1
br label %23
8: ; preds = %0
%9 = call i8* @ctime(i64* %2)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %8
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %22
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = call i8* @strchr(i8* %14, i8 signext 10)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
br label %21
21: ; preds = %18, %13
br label %22
22: ; preds = %21, %12
br label %23
23: ; preds = %22, %7
%24 = load i8*, i8** %1
ret i8* %24
}

LLVM IR (-O2):
@.str = [18 x i8] c"<time read error>\00"
@.str.1 = [20 x i8] c"<time format error>\00"
define i8* @get_time_formatted() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i64 @time(i32* null)
store i64 %3, i64* %1
%4 = icmp slt i64 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = call i8* @ctime(i64* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = call i8* @strchr(i8* %6, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 0, i8* %9
br label %12
12: ; preds = %8, %11, %5, %0
%13 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %5 ], [ %6, %11 ], [ %6, %8 ]
ret i8* %13
}