#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 */
char *asctime(struct tm *);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int time(int /*<<< orphan*/ *);
char *get_time_str(char *time_buf) {
  time_t now_sec;
  struct tm *time_now;
  if (time(&now_sec) == -1) {
    perror("time() in get_time.c");
    return NULL;
  }
  if ((time_now = gmtime(&now_sec)) == NULL) {
    perror("localtime in get_time.c");
    return NULL;
  }
  char *str_ptr = NULL;
  if ((str_ptr = asctime(time_now)) == NULL) {
    perror("asctime in get_time.c");
    return NULL;
  }
  strcat(time_buf, str_ptr);
  return time_buf;
}


x86 assembly (clang, -O0):
<get_time_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <time@plt>
cmp    $0xffffffff,%eax
jne    1187 <get_time_str+0x37>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <get_time_str+0xb4>
lea    -0x14(%rbp),%rdi
call   1060 <gmtime@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b7 <get_time_str+0x67>
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <get_time_str+0xb4>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <asctime@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ef <get_time_str+0x9f>
lea    0xe50(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <get_time_str+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_str>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
call   1040 <time@plt>
cmp    $0xffffffff,%eax
je     1197 <get_time_str+0x47>
lea    0xc(%rsp),%rdi
call   1060 <gmtime@plt>
test   %rax,%rax
je     11a0 <get_time_str+0x50>
mov    %rax,%rdi
call   1030 <asctime@plt>
test   %rax,%rax
je     11a9 <get_time_str+0x59>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe62(%rip),%rdi
jmp    11b0 <get_time_str+0x60>
lea    0xe6e(%rip),%rdi
jmp    11b0 <get_time_str+0x60>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
xor    %ebx,%ebx
jmp    118e <get_time_str+0x3e>

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [21 x i8] c"time() in get_time.c\00"
@.str.1 = [24 x i8] c"localtime in get_time.c\00"
@.str.2 = [22 x i8] c"asctime in get_time.c\00"
define i8* @get_time_str(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @time(i32* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = call %struct.tm* @gmtime(i32* %2)
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %20
13: ; preds = %8
%14 = call i8* @asctime(%struct.tm* %9)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 @strcat(i8* %0, i8* %14)
br label %20
20: ; preds = %16, %18, %11, %6
%21 = phi i8* [ null, %6 ], [ null, %11 ], [ null, %16 ], [ %0, %18 ]
ret i8* %21
}