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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void fprint_timestamp(FILE *fd, const char *file, int line, const char *func,
                      int priority, const char *message, const char *appendix) {
  struct tm *ptm;
  time_t t;
  char buf[200];
  t = time(NULL);
  ptm = localtime(&t);
  if (ptm == NULL || strftime(buf, sizeof(buf), "%F %T", ptm) == 0) {
    if (appendix)
      fprintf(fd, "%s:%u %s(...) %s: %s\n", file, line, func, message,
              appendix);
    else
      fprintf(fd, "%s:%u %s(...) %s\n", file, line, func, message);
  } else {
    if (appendix)
      fprintf(fd, "%s %s:%u %s(...) %s: %s\n", buf, file, line, func, message,
              appendix);
    else
      fprintf(fd, "%s %s:%u %s(...) %s\n", buf, file, line, func, message);
  }
}


x86 assembly (clang, -O0):
<fprint_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x3c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b0 <fprint_timestamp+0x70>
lea    -0x110(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0xc8,%esi
lea    0xe5f(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    120f <fprint_timestamp+0xcf>
cmpq   $0x0,0x10(%rbp)
je     11e9 <fprint_timestamp+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%rax
lea    0xe30(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    120a <fprint_timestamp+0xca>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1287 <fprint_timestamp+0x147>
cmpq   $0x0,0x10(%rbp)
je     1255 <fprint_timestamp+0x115>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x30(%rbp),%r10
mov    0x10(%rbp),%rax
lea    0xdc6(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1282 <fprint_timestamp+0x142>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x30(%rbp),%rax
lea    0xda8(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1287 <fprint_timestamp+0x147>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_timestamp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %r9,%rbp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x120(%rsp),%r13
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x1c(%rsp)
lea    0x1c(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11b7 <fprint_timestamp+0x77>
lea    0xe77(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0xc8,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
je     11b7 <fprint_timestamp+0x77>
test   %r13,%r13
je     11e8 <fprint_timestamp+0xa8>
mov    %r13,0x8(%rsp)
mov    %rbp,(%rsp)
lea    0xe51(%rip),%rsi
jmp    11f3 <fprint_timestamp+0xb3>
test   %r13,%r13
je     11c9 <fprint_timestamp+0x89>
mov    %r13,(%rsp)
lea    0xe42(%rip),%rsi
jmp    11d0 <fprint_timestamp+0x90>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r14,%r8
mov    %rbp,%r9
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    120b <fprint_timestamp+0xcb>
mov    %rbp,(%rsp)
lea    0xe2c(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14,%r9
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [22 x i8] c"%s:%u %s(...) %s: %s\0A\00"
@.str.2 = [18 x i8] c"%s:%u %s(...) %s\0A\00"
@.str.3 = [25 x i8] c"%s %s:%u %s(...) %s: %s\0A\00"
@.str.4 = [21 x i8] c"%s %s:%u %s(...) %s\0A\00"
define void @fprint_timestamp(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5, i8* %6) {
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca %struct.tm*
%16 = alloca i32
%17 = alloca [200 x i8]
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%18 = call i32 @time(i32* null)
store i32 %18, i32* %16
%19 = call %struct.tm* @localtime(i32* %16)
store %struct.tm* %19, %struct.tm** %15
%20 = load %struct.tm*, %struct.tm** %15
%21 = icmp eq %struct.tm* %20, null
br i1 %21, label %27, label %22
22: ; preds = %7
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %17, i64 0, i64 0
%24 = load %struct.tm*, %struct.tm** %15
%25 = call i64 @strftime(i8* %23, i32 200, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %22, %7
%28 = load i8*, i8** %14
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32*, i32** %8
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = load i8*, i8** %11
%35 = load i8*, i8** %13
%36 = load i8*, i8** %14
%37 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33, i8* %34, i8* %35, i8* %36)
br label %45
38: ; preds = %27
%39 = load i32*, i32** %8
%40 = load i8*, i8** %9
%41 = load i32, i32* %10
%42 = load i8*, i8** %11
%43 = load i8*, i8** %13
%44 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %40, i32 %41, i8* %42, i8* %43)
br label %45
45: ; preds = %38, %30
br label %67
46: ; preds = %22
%47 = load i8*, i8** %14
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %58
49: ; preds = %46
%50 = load i32*, i32** %8
%51 = getelementptr inbounds [200 x i8], [200 x i8]* %17, i64 0, i64 0
%52 = load i8*, i8** %9
%53 = load i32, i32* %10
%54 = load i8*, i8** %11
%55 = load i8*, i8** %13
%56 = load i8*, i8** %14
%57 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52, i32 %53, i8* %54, i8* %55, i8* %56)
br label %66
58: ; preds = %46
%59 = load i32*, i32** %8
%60 = getelementptr inbounds [200 x i8], [200 x i8]* %17, i64 0, i64 0
%61 = load i8*, i8** %9
%62 = load i32, i32* %10
%63 = load i8*, i8** %11
%64 = load i8*, i8** %13
%65 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %60, i8* %61, i32 %62, i8* %63, i8* %64)
br label %66
66: ; preds = %58, %49
br label %67
67: ; preds = %66, %45
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [22 x i8] c"%s:%u %s(...) %s: %s\0A\00"
@.str.2 = [18 x i8] c"%s:%u %s(...) %s\0A\00"
@.str.3 = [25 x i8] c"%s %s:%u %s(...) %s: %s\0A\00"
@.str.4 = [21 x i8] c"%s %s:%u %s(...) %s\0A\00"
define void @fprint_timestamp(i32* nocapture %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca [200 x i8]
%10 = bitcast i32* %8 to i8*
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%12 = tail call i32 @time(i32* null)
store i32 %12, i32* %8
%13 = call %struct.tm* @localtime(i32* %8)
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = call i64 @strftime(i8* %11, i32 200, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15, %7
%19 = icmp eq i8* %6, null
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2, i8* %3, i8* %5, i8* %6)
br label %30
22: ; preds = %18
%23 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %2, i8* %3, i8* %5)
br label %30
24: ; preds = %15
%25 = icmp eq i8* %6, null
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %1, i32 %2, i8* %3, i8* %5, i8* %6)
br label %30
28: ; preds = %24
%29 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %11, i8* %1, i32 %2, i8* %3, i8* %5)
br label %30
30: ; preds = %26, %28, %20, %22
ret void
}