#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_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(unsigned char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char const *,
                           ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(unsigned char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/);
void write_output(unsigned char const *name,
                  const unsigned char *variable_prefix,
                  const unsigned char *version_string) {
  FILE *f;
  time_t t;
  struct tm *ptm = 0;
  t = time(0);
  ptm = localtime(&t);
  remove(name);
  if (!(f = fopen(name, "w"))) {
    fprintf(stderr, "%s: cannot open for writing\n", name);
    exit(1);
  }
  if (!variable_prefix)
    variable_prefix = "compile";
  fprintf(f,
          "/* THIS IS AUTOGENERATED FILE */\n"
          "char const %s_version[] = \"%s\";\n"
          "char const %s_date[] = \"%04d-%02d-%02d %02d:%02d:%02d\";\n",
          variable_prefix, version_string, variable_prefix, ptm->tm_year + 1900,
          ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
          ptm->tm_sec);
  fclose(f);
}


x86 assembly (clang, -O0):
<write_output>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,-0x34(%rbp)
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f3 <write_output+0x83>
mov    0x2e0c(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1209 <write_output+0x99>
lea    0xe1a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x40(%rbp),%rax
mov    (%rax),%r9d
add    $0x76c,%r9d
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%r14d
add    $0x1,%r14d
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%ebx
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xdcf(%rip),%rsi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_output>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <remove@plt>
lea    0xe53(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1229 <write_output+0xb9>
mov    %rax,%r13
test   %r12,%r12
lea    0xe58(%rip),%rdx
cmovne %r12,%rdx
mov    $0x76c,%r9d
add    (%rbx),%r9d
mov    0x4(%rbx),%r10d
mov    0x8(%rbx),%r11d
add    $0x1,%r10d
mov    0xc(%rbx),%r15d
mov    0x10(%rbx),%r12d
mov    0x14(%rbx),%ebx
sub    $0x8,%rsp
lea    0xe31(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rcx
mov    %rdx,%r8
xor    %eax,%eax
push   %rbx
push   %r12
push   %r15
push   %r11
push   %r10
call   1060 <fprintf@plt>
add    $0x30,%rsp
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2db0(%rip),%rax
movslq (%rax),%rdi
lea    0xdc8(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"%s: cannot open for writing\0A\00"
@.str.2 = [8 x i8] c"compile\00"
@.str.3 = [122 x i8] c"/* THIS IS AUTOGENERATED FILE */\0Achar const %s_version[] = \22%s\22;\0Achar const %s_date[] = \22%04d-%02d-%02d %02d:%02d:%02d\22;\0A\00"
define void @write_output(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.tm*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store %struct.tm* null, %struct.tm** %9
%10 = call i32 @time(i32 0)
store i32 %10, i32* %8
%11 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %11, %struct.tm** %9
%12 = load i8*, i8** %4
%13 = call i32 @remove(i8* %12)
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %24, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = load i8*, i8** %4
%22 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %24
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %28
28: ; preds = %27, %24
%29 = load i32*, i32** %7
%30 = load i8*, i8** %5
%31 = load i8*, i8** %6
%32 = load i8*, i8** %5
%33 = load %struct.tm*, %struct.tm** %9
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1900
%37 = load %struct.tm*, %struct.tm** %9
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
%41 = load %struct.tm*, %struct.tm** %9
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 2
%43 = load i32, i32* %42
%44 = load %struct.tm*, %struct.tm** %9
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 3
%46 = load i32, i32* %45
%47 = load %struct.tm*, %struct.tm** %9
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 4
%49 = load i32, i32* %48
%50 = load %struct.tm*, %struct.tm** %9
%51 = getelementptr inbounds %struct.tm, %struct.tm* %50, i32 0, i32 5
%52 = load i32, i32* %51
%53 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %31, i8* %32, i32 %36, i32 %40, i32 %43, i32 %46, i32 %49, i32 %52)
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"%s: cannot open for writing\0A\00"
@.str.2 = [8 x i8] c"compile\00"
@.str.3 = [122 x i8] c"/* THIS IS AUTOGENERATED FILE */\0Achar const %s_version[] = \22%s\22;\0Achar const %s_date[] = \22%04d-%02d-%02d %02d:%02d:%02d\22;\0A\00"
define void @write_output(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @time(i32 0)
store i32 %6, i32* %4
%7 = call %struct.tm* @localtime(i32* %4)
%8 = call i32 @remove(i8* %0)
%9 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = icmp eq i8* %1, null
%19 = select i1 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%33 = load i32, i32* %32
%34 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %2, i8* %19, i32 %22, i32 %25, i32 %27, i32 %29, i32 %31, i32 %33)
%35 = call i32 @fclose(i32* %9)
ret void
}