#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;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(scalar_t__ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
scalar_t__ time(scalar_t__ *);
int get_timestr(char *buff, int size) {
  time_t now;
  struct tm *now_time;
  if (time(&now) == (time_t)(-1)) {
    printf("Unable to retrieve current time\n");
    return -1;
  }
  if ((now_time = localtime(&now)) == NULL) {
    printf("Unable to transform date and time to broken-down time or ASCII\n");
    return -1;
  }
  if ((strftime(buff, size, "%x %X", now_time)) == 0) {
    printf("Unable to format date and time\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_timestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <time@plt>
cmp    $0xffffffffffffffff,%rax
jne    117a <get_timestr+0x3a>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <get_timestr+0xa9>
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a9 <get_timestr+0x69>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <get_timestr+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rcx
lea    0xea6(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    11e2 <get_timestr+0xa2>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <get_timestr+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timestr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1050 <time@plt>
cmp    $0xffffffffffffffff,%rax
je     118a <get_timestr+0x4a>
mov    %rsp,%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1193 <get_timestr+0x53>
lea    0xe96(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a4 <get_timestr+0x64>
lea    0xe7e(%rip),%rdi
jmp    119a <get_timestr+0x5a>
lea    0xed3(%rip),%rdi
jmp    119a <get_timestr+0x5a>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [33 x i8] c"Unable to retrieve current time\0A\00"
@.str.1 = [64 x i8] c"Unable to transform date and time to broken-down time or ASCII\0A\00"
@.str.2 = [6 x i8] c"%x %X\00"
@.str.3 = [32 x i8] c"Unable to format date and time\0A\00"
define i32 @get_timestr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.tm*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i64 @time(i64* %6)
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
12: ; preds = %2
%13 = call %struct.tm* @localtime(i64* %6)
store %struct.tm* %13, %struct.tm** %7
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = load %struct.tm*, %struct.tm** %7
%21 = call i64 @strftime(i8* %18, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
25: ; preds = %17
store i32 0, i32* %3
br label %26
26: ; preds = %25, %23, %15, %10
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str.2 = [6 x i8] c"%x %X\00"
@str = [31 x i8] c"Unable to format date and time\00"
@str.4 = [63 x i8] c"Unable to transform date and time to broken-down time or ASCII\00"
@str.5 = [32 x i8] c"Unable to retrieve current time\00"
define i32 @get_timestr(i8* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i64 @time(i64* %3)
%6 = icmp eq i64 %5, -1
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = call %struct.tm* @localtime(i64* %3)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i64 @strftime(i8* %0, i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10, %7, %2
%14 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0), %2 ], [ getelementptr inbounds ([63 x i8], [63 x i8]* @str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), %10 ]
%15 = call i32 @puts(i8* dereferenceable(1) %14)
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ 0, %10 ], [ -1, %13 ]
ret i32 %17
}