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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
int main() {
  time_t t;
  struct tm *pt;
  char buf[256];
  if (time(&t) == (-1)) {
    fprintf(stderr, "Unable to get the current time.\n");
    fflush(stderr);
    return 1;
  }
  if ((pt = localtime(&t)) == NULL) {
    fprintf(stderr, "Unable to decode time value.\n");
    fflush(stderr);
    return 1;
  }
  if (strftime(buf, sizeof(buf), "%Y%m%d", pt) == 0) {
    fprintf(stderr, "Unable to format time string.\n");
    fflush(stderr);
    return 1;
  }
  printf("#define YYYYMMDD \"%s\"\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <time@plt>
cmp    $0xffffffff,%eax
jne    11b3 <main+0x53>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f9 <main+0x99>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe2f(%rip),%rdx
call   1080 <strftime@plt>
cmp    $0x0,%rax
jne    124e <main+0xee>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
lea    -0x110(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
lea    0xc(%rsp),%rdi
call   1060 <time@plt>
cmp    $0xffffffff,%eax
je     11b9 <main+0x59>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11cb <main+0x6b>
lea    0xeb2(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
test   %rax,%rax
je     11dd <main+0x7d>
lea    0xeba(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11fe <main+0x9e>
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
lea    0xe37(%rip),%rsi
jmp    11ed <main+0x8d>
mov    0x2e0e(%rip),%rbx
mov    (%rbx),%edi
lea    0xe46(%rip),%rsi
jmp    11ed <main+0x8d>
mov    0x2dfc(%rip),%rbx
mov    (%rbx),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
mov    $0x1,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Unable to get the current time.\0A\00"
@.str.1 = [30 x i8] c"Unable to decode time value.\0A\00"
@.str.2 = [7 x i8] c"%Y%m%d\00"
@.str.3 = [31 x i8] c"Unable to format time string.\0A\00"
@.str.4 = [23 x i8] c"#define YYYYMMDD \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = call i32 @time(i32* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = call i32 @fflush(i32 %10)
store i32 1, i32* %1
br label %33
12: ; preds = %0
%13 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %13, %struct.tm** %3
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fflush(i32 %18)
store i32 1, i32* %1
br label %33
20: ; preds = %12
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = load %struct.tm*, %struct.tm** %3
%23 = call i64 @strftime(i8* %21, i32 256, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 @fflush(i32 %28)
store i32 1, i32* %1
br label %33
30: ; preds = %20
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %31)
store i32 0, i32* %1
br label %33
33: ; preds = %30, %25, %15, %7
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Unable to get the current time.\0A\00"
@.str.1 = [30 x i8] c"Unable to decode time value.\0A\00"
@.str.2 = [7 x i8] c"%Y%m%d\00"
@.str.3 = [31 x i8] c"Unable to format time string.\0A\00"
@.str.4 = [23 x i8] c"#define YYYYMMDD \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = call i32 @time(i32* %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = call i32 @fflush(i32 %10)
br label %30
12: ; preds = %0
%13 = call %struct.tm* @localtime(i32* %1)
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fflush(i32 %18)
br label %30
20: ; preds = %12
%21 = call i64 @strftime(i8* %4, i32 256, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %13)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 @fflush(i32 %26)
br label %30
28: ; preds = %20
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %30
30: ; preds = %28, %23, %15, %7
%31 = phi i32 [ 1, %7 ], [ 1, %15 ], [ 1, %23 ], [ 0, %28 ]
ret i32 %31
}