#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 tm_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int pid_t;

/* Variables and functions */
int getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *dub_stamp(void) {
  static char timestring[35];
  struct tm *tmp;
  time_t currt = time(NULL);
  static pid_t pid = 0;
  if (!pid)
    pid = getpid();
  tmp = localtime(&currt);
  snprintf(timestring, 35, "[%02d/%02d/%4d:%02d:%02d:%02d|%u] ", tmp->tm_mday,
           tmp->tm_mon, 1900 + tmp->tm_year, tmp->tm_hour, tmp->tm_min,
           tmp->tm_sec, pid);
  return timestring;
}


x86 assembly (clang, -O0):
<dub_stamp>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,0x2f18(%rip)
jne    116f <dub_stamp+0x2f>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,0x2f05(%rip)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r9d
add    $0x76c,%r9d
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%ebx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r11d
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%r10d
mov    0x2ebe(%rip),%eax
lea    0x2e93(%rip),%rdi
mov    $0x23,%esi
lea    0xe37(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1050 <snprintf@plt>
lea    0x2e6a(%rip),%rax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<dub_stamp>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0x4(%rsp)
cmpl   $0x0,0x2f1e(%rip)
jne    1165 <dub_stamp+0x25>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x2f0f(%rip)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    $0x76c,%r9d
add    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0x14(%rax),%eax
mov    0x2ee4(%rip),%ebx
lea    0x2eb9(%rip),%r14
lea    0xe62(%rip),%rdx
mov    %r14,%rdi
mov    $0x23,%esi
push   %rbx
push   %rax
push   %r11
push   %r10
call   1050 <snprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@dub_stamp.timestring = internal global [35 x i8] zeroinitializer
@dub_stamp.pid = internal global i32 0
@.str = [35 x i8] c"[%02d/%02d/%4d:%02d:%02d:%02d|%u] \00"
define i8* @dub_stamp() {
%1 = alloca %struct.tm*
%2 = alloca i32
%3 = call i32 @time(i32* null)
store i32 %3, i32* %2
%4 = load i32, i32* @dub_stamp.pid
%5 = icmp ne i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 (...) @getpid()
store i32 %7, i32* @dub_stamp.pid
br label %8
8: ; preds = %6, %0
%9 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %9, %struct.tm** %1
%10 = load %struct.tm*, %struct.tm** %1
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.tm*, %struct.tm** %1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.tm*, %struct.tm** %1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = add nsw i32 1900, %18
%20 = load %struct.tm*, %struct.tm** %1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 3
%22 = load i32, i32* %21
%23 = load %struct.tm*, %struct.tm** %1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 4
%25 = load i32, i32* %24
%26 = load %struct.tm*, %struct.tm** %1
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i32 0, i32 5
%28 = load i32, i32* %27
%29 = load i32, i32* @dub_stamp.pid
%30 = call i32 @snprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @dub_stamp.timestring, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %19, i32 %22, i32 %25, i32 %28, i32 %29)
ret i8* getelementptr inbounds ([35 x i8], [35 x i8]* @dub_stamp.timestring, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@dub_stamp.timestring = internal global [35 x i8] zeroinitializer
@dub_stamp.pid = internal unnamed_addr global i32 0
@.str = [35 x i8] c"[%02d/%02d/%4d:%02d:%02d:%02d|%u] \00"
define i8* @dub_stamp() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = load i32, i32* @dub_stamp.pid
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (...) @getpid()
store i32 %7, i32* @dub_stamp.pid
br label %8
8: ; preds = %6, %0
%9 = call %struct.tm* @localtime(i32* %1)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 2
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
%17 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 3
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 4
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 5
%22 = load i32, i32* %21
%23 = load i32, i32* @dub_stamp.pid
%24 = call i32 @snprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @dub_stamp.timestring, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13, i32 %16, i32 %18, i32 %20, i32 %22, i32 %23)
ret i8* getelementptr inbounds ([35 x i8], [35 x i8]* @dub_stamp.timestring, i64 0, i64 0)
}