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

/* Variables and functions */
int /*<<< orphan*/ asctime(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  FILE *f;
  ulong build = 0, build_t;
  char s[25];
  time_t tm;
  if (f = fopen("version.bin", "rb")) {
    if (1 == fread(&build_t, sizeof build_t, 1, f))
      build = build_t;
  }
  ++build;
  time(&tm);
  memcpy(s, asctime(localtime(&tm)), 24);
  s[24] = 0;
  if (f = fopen("verstub.cpp", "w")) {
    fprintf(f,
            "unsigned long version_num = %ld;\n"
            "const char *version_time = \"%s\";\n",
            build, s);
    fclose(f);
  }
  if (f = fopen("version.bin", "wb")) {
    fwrite(&build, sizeof build, 1, f);
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe52(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11fb <main+0x6b>
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11f6 <main+0x66>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11fb <main+0x6b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x44(%rbp),%rdi
call   1090 <time@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x44(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    $0x18,%edx
call   1080 <memcpy@plt>
movb   $0x0,-0x28(%rbp)
lea    0xdcc(%rip),%rdi
lea    0xdd1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     127e <main+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    0xdad(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd7b(%rip),%rdi
lea    0xdd4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     12bf <main+0x12f>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe62(%rip),%rdi
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11d2 <main+0x42>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11d2 <main+0x42>
mov    0x8(%rsp),%r14
jmp    11d5 <main+0x45>
xor    %r14d,%r14d
add    $0x1,%r14
mov    %r14,0x10(%rsp)
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
lea    0x20(%rsp),%rdi
mov    %eax,%esi
mov    $0x18,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x38(%rsp)
lea    0xdf8(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     124a <main+0xba>
mov    %rax,%rbx
lea    0xdeb(%rip),%rsi
lea    0x20(%rsp),%rcx
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdaf(%rip),%rdi
lea    0xe08(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1284 <main+0xf4>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"version.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [12 x i8] c"verstub.cpp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [67 x i8] c"unsigned long version_num = %ld;\0Aconst char *version_time = \22%s\22;\0A\00"
@.str.5 = [3 x i8] c"wb\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [25 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fread(i8** %4, i32 8, i32 1, i32* %10)
%12 = icmp eq i32 1, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i8*, i8** %4
store i8* %14, i8** %3
br label %15
15: ; preds = %13, %9
br label %16
16: ; preds = %15, %0
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = call i32 @time(i32* %6)
%20 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%21 = call i32 @localtime(i32* %6)
%22 = call i32 @asctime(i32 %21)
%23 = call i32 @memcpy(i8* %20, i32 %22, i32 24)
%24 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 24
store i8 0, i8* %24
%25 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %2
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %34
27: ; preds = %16
%28 = load i32*, i32** %2
%29 = load i8*, i8** %3
%30 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%31 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %29, i8* %30)
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %27, %16
%35 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %35, i32** %2
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32*, i32** %2
%39 = call i32 @fwrite(i8** %3, i32 8, i32 1, i32* %38)
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %37, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"version.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [12 x i8] c"verstub.cpp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [67 x i8] c"unsigned long version_num = %ld;\0Aconst char *version_time = \22%s\22;\0A\00"
@.str.5 = [3 x i8] c"wb\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [25 x i8]
%4 = alloca i32
%5 = bitcast i8** %1 to i8*
%6 = bitcast i8** %2 to i8*
%7 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %0
%12 = call i32 @fread(i8** %2, i32 8, i32 1, i32* %9)
%13 = icmp eq i32 %12, 1
%14 = load i8*, i8** %2
%15 = select i1 %13, i8* %14, i8* null
br label %16
16: ; preds = %11, %0
%17 = phi i8* [ null, %0 ], [ %15, %11 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %1
%19 = call i32 @time(i32* %4)
%20 = call i32 @localtime(i32* %4)
%21 = call i32 @asctime(i32 %20)
%22 = call i32 @memcpy(i8* %7, i32 %21, i32 24)
%23 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 24
store i8 0, i8* %23
%24 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %16
%27 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* %7)
%28 = call i32 @fclose(i32* %24)
br label %29
29: ; preds = %26, %16
%30 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i32 @fwrite(i8** %1, i32 8, i32 1, i32* %30)
%34 = call i32 @fclose(i32* %30)
br label %35
35: ; preds = %32, %29
ret i32 0
}