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

/* Variables and functions */
int /*<<< orphan*/ ctime_r(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ getpid();
int log_message(int /*<<< orphan*/ *, char *, int /*<<< orphan*/, char *);
int open_log();
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int log_time(FILE *log) {
  if (!log) {
    int rc = open_log();
    if (rc < 0)
      return rc;
  }
  time_t t = time(NULL);
  char timestr[27];
  ctime_r(&t, timestr);
  timestr[26] = '\0';
  for (int i = 26; i >= 0; i--)
    if (timestr[i] == '\n')
      timestr[i] = '\0';
  return log_message(log, "DBG: %d: %s: ", getpid(), timestr);
}


x86 assembly (clang, -O0):
<log_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <log_time+0x3b>
mov    $0x0,%al
call   1040 <open_log@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1186 <log_time+0x36>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <log_time+0xbf>
jmp    118b <log_time+0x3b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x18(%rbp)
lea    -0x40(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1060 <ctime_r@plt>
movb   $0x0,-0x26(%rbp)
movl   $0x1a,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     11e7 <log_time+0x97>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11d4 <log_time+0x84>
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
jmp    11d9 <log_time+0x89>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    11af <log_time+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    -0x40(%rbp),%rcx
lea    0xdf9(%rip),%rsi
call   1070 <log_message@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_time>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
test   %rdi,%rdi
jne    116e <log_time+0x1e>
xor    %eax,%eax
call   1040 <open_log@plt>
test   %eax,%eax
js     120f <log_time+0xbf>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <ctime_r@plt>
movb   $0x0,0x2a(%rsp)
mov    $0x1a,%eax
cmp    $0xa,%bl
je     11c0 <log_time+0x70>
nopl   0x0(%rax)
cmpb   $0xa,0xf(%rsp,%rax,1)
je     11cc <log_time+0x7c>
cmpb   $0xa,0xe(%rsp,%rax,1)
je     11d8 <log_time+0x88>
cmp    $0x2,%rax
jne    11e3 <log_time+0x93>
jmp    11f2 <log_time+0xa2>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,0x10(%rsp,%rax,1)
cmpb   $0xa,0xf(%rsp,%rax,1)
jne    11a7 <log_time+0x57>
movb   $0x0,0xf(%rsp,%rax,1)
cmpb   $0xa,0xe(%rsp,%rax,1)
jne    11ae <log_time+0x5e>
movb   $0x0,0xe(%rsp,%rax,1)
cmp    $0x2,%rax
je     11f2 <log_time+0xa2>
mov    0xd(%rsp,%rax,1),%bl
add    $0xfffffffffffffffd,%rax
cmp    $0xa,%bl
je     11c0 <log_time+0x70>
jmp    11a0 <log_time+0x50>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe00(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %eax,%edx
call   1070 <log_message@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"DBG: %d: %s: \00"
define i32 @log_time(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [27 x i8]
%7 = alloca i32
store i32* %0, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = call i32 (...) @open_log()
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %45
16: ; preds = %10
br label %17
17: ; preds = %16, %1
%18 = call i32 @time(i32* null)
store i32 %18, i32* %5
%19 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 0
%20 = call i32 @ctime_r(i32* %5, i8* %19)
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 26
store i8 0, i8* %21
store i32 26, i32* %7
br label %22
22: ; preds = %37, %17
%23 = load i32, i32* %7
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %32, %25
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, -1
store i32 %39, i32* %7
br label %22
40: ; preds = %22
%41 = load i32*, i32** %3
%42 = call i32 (...) @getpid()
%43 = getelementptr inbounds [27 x i8], [27 x i8]* %6, i64 0, i64 0
%44 = call i32 @log_message(i32* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %42, i8* %43)
store i32 %44, i32* %2
br label %45
45: ; preds = %40, %14
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"DBG: %d: %s: \00"
define i32 @log_time(i32* %0) {
%2 = alloca i32
%3 = alloca [27 x i8]
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 (...) @open_log()
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %43
8: ; preds = %5, %1
%9 = bitcast i32* %2 to i8*
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %2
%11 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%12 = call i32 @ctime_r(i32* %2, i8* %11)
%13 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 26
store i8 0, i8* %13
br label %17
14: ; preds = %37
%15 = call i32 (...) @getpid()
%16 = call i32 @log_message(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %11)
br label %43
17: ; preds = %40, %8
%18 = phi i8 [ 0, %8 ], [ %42, %40 ]
%19 = phi i64 [ 26, %8 ], [ %38, %40 ]
%20 = icmp eq i8 %18, 10
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %22
br label %23
23: ; preds = %17, %21
%24 = add nsw i64 %19, -1
%25 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %29
br label %30
30: ; preds = %28, %23
%31 = add nsw i64 %19, -2
%32 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %31
store i8 0, i8* %36
br label %37
37: ; preds = %35, %30
%38 = add nsw i64 %19, -3
%39 = icmp eq i64 %31, 0
br i1 %39, label %14, label %40
40: ; preds = %37
%41 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 %38
%42 = load i8, i8* %41
br label %17
43: ; preds = %5, %14
%44 = phi i32 [ %16, %14 ], [ %6, %5 ]
ret i32 %44
}