#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;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fprintf(int /*<<< orphan*/ *, char *, char *);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *localtime_r(int /*<<< orphan*/ *, struct tm *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int logprintdate(FILE *stream) {
  struct timeval tv;
  time_t now;
  struct tm tmnow;
  char buf[32];
  if (gettimeofday(&tv, NULL) == -1)
    return -1;
  now = tv.tv_sec;
  if (localtime_r(&now, &tmnow) == NULL)
    return -1;
  if (strftime(buf, sizeof(buf), "%b %d %T ", &tmnow) == 0)
    return -1;
  return fprintf(stream, "%s", buf);
}


x86 assembly (clang, -O0):
<logprintdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    116e <logprintdate+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <logprintdate+0x9d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    1197 <logprintdate+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <logprintdate+0x9d>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
lea    0xe59(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    11c6 <logprintdate+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <logprintdate+0x9d>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logprintdate>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11ad <logprintdate+0x6d>
mov    0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11ad <logprintdate+0x6d>
lea    0xe80(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x20,%esi
call   1060 <strftime@plt>
test   %rax,%rax
je     11ad <logprintdate+0x6d>
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fprintf@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [10 x i8] c"%b %d %T \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @logprintdate(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca [32 x i8]
store i32* %0, i32** %3
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %26
11: ; preds = %1
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = call i32* @localtime_r(i32* %5, %struct.tm* %6)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 -1, i32* %2
br label %26
17: ; preds = %11
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%19 = call i64 @strftime(i8* %18, i32 32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %2
br label %26
22: ; preds = %17
%23 = load i32*, i32** %3
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 %25, i32* %2
br label %26
26: ; preds = %22, %21, %16, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [10 x i8] c"%b %d %T \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @logprintdate(i32* nocapture %0) {
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca [32 x i8]
%6 = bitcast %struct.timeval* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.tm* %4 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %22, label %12
12: ; preds = %1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %3
%15 = call i32* @localtime_r(i32* %3, %struct.tm* %4)
%16 = icmp eq i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = call i64 @strftime(i8* %9, i32 32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %22
22: ; preds = %17, %12, %1, %20
%23 = phi i32 [ %21, %20 ], [ -1, %1 ], [ -1, %12 ], [ -1, %17 ]
ret i32 %23
}