#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;

/* Variables and functions */
int /*<<< orphan*/ ctime(scalar_t__ *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ time(scalar_t__ *);
char *mytimestamp(int mode) {
  static char tmbuf[128];
  time_t tmtick;
  time(&tmtick);
  if (mode == 0) {
    sprintf(tmbuf, "%u", (unsigned)tmtick);
  } else {
    strcpy(tmbuf, ctime(&tmtick));
    tmbuf[strlen(tmbuf) - 1] = 0;
  }
  return tmbuf;
}


x86 assembly (clang, -O0):
<mytimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1060 <time@plt>
cmpl   $0x0,-0x4(%rbp)
jne    118c <mytimestamp+0x3c>
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0x2ee5(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <sprintf@plt>
jmp    11c0 <mytimestamp+0x70>
lea    -0x10(%rbp),%rdi
call   1040 <ctime@plt>
mov    %eax,%esi
lea    0x2ec2(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2eb6(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ea4(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e99(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mytimestamp>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
call   1060 <time@plt>
test   %ebx,%ebx
je     1191 <mytimestamp+0x41>
lea    0x8(%rsp),%rdi
call   1040 <ctime@plt>
lea    0x2eea(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    11a8 <mytimestamp+0x58>
mov    0x8(%rsp),%edx
lea    0x2ec4(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <sprintf@plt>
lea    0x2eb1(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@mytimestamp.tmbuf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @mytimestamp(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
%4 = call i32 @time(i64* %3)
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i64, i64* %3
%9 = trunc i64 %8 to i32
%10 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %18
11: ; preds = %1
%12 = call i32 @ctime(i64* %3)
%13 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0), i32 %12)
%14 = call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0))
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %11, %7
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@mytimestamp.tmbuf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @mytimestamp(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i32 @time(i64* %2)
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i64, i64* %2
%8 = trunc i64 %7 to i32
%9 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %17
10: ; preds = %1
%11 = call i32 @ctime(i64* %2)
%12 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0), i32 %11)
%13 = call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0))
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %10, %6
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mytimestamp.tmbuf, i64 0, i64 0)
}