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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
scalar_t__ cuserid(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  time_t now;
  FILE *ofp;
  char *dateval;
  char *username;
  char *userstr;
  char *datestr;
  int i;
  char propname[32];
  char *propvalue;
  char timestr[64];
  char *cp;
  if (argc < 4) {
    printf("usage: mkversion ostype version outputfile\n");
    exit(1);
  }
  ofp = fopen(argv[3], "w");
  if (ofp == NULL) {
    printf("Couldn't create %s\n", argv[3]);
    exit(1);
  }
  now = time(0);
  fprintf(ofp, "/*\n");
  fprintf(ofp, " * G2 Version Stamp, %s", ctime(&now));
  fprintf(ofp, " * Automatically generated, hand edits are pointless.\n");
  fprintf(ofp, " */\n\n");
  fprintf(ofp, "const char *version_string = \"G2 (%s) major version %s\";\n",
          argv[1], argv[2]);
  username = (char *)cuserid(0);
  strcpy(timestr, ctime(&now));
  cp = timestr;
  while (*cp) {
    cp++;
  }
  if (*--cp == '\n')
    *cp = 0;
  fprintf(ofp, "const char *minor_v_string = \"Built by %s at %s\";\n",
          username, timestr);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fe <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xd8(%rbp),%rdi
mov    %rax,%rdx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <cuserid@plt>
mov    %rax,-0x30(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xd0(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12f2 <main+0x172>
mov    -0xc8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc8(%rbp)
jmp    12cb <main+0x14b>
mov    -0xc8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0xc8(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    131e <main+0x19e>
mov    -0xc8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
cmp    $0x3,%edi
jg     11c4 <main+0x24>
lea    0xf27(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xe2e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    11f8 <main+0x58>
mov    0x18(%rbx),%rsi
lea    0xe1b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xe09(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1050 <ctime@plt>
lea    0xde7(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x36,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
lea    0xe09(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xdee(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <cuserid@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <ctime@plt>
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    0xe(%rsp),%rax
nop
cmpb   $0x0,0x2(%rax)
lea    0x1(%rax),%rax
jne    12b0 <main+0x110>
cmpb   $0xa,(%rax)
jne    12c2 <main+0x122>
movb   $0x0,(%rax)
lea    0xde0(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"usage: mkversion ostype version outputfile\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Couldn't create %s\0A\00"
@.str.3 = [4 x i8] c"/*\0A\00"
@.str.4 = [24 x i8] c" * G2 Version Stamp, %s\00"
@.str.5 = [55 x i8] c" * Automatically generated, hand edits are pointless.\0A\00"
@.str.6 = [6 x i8] c" */\0A\0A\00"
@.str.7 = [58 x i8] c"const char *version_string = \22G2 (%s) major version %s\22;\0A\00"
@.str.8 = [51 x i8] c"const char *minor_v_string = \22Built by %s at %s\22;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [32 x i8]
%14 = alloca i8*
%15 = alloca [64 x i8]
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %35
29: ; preds = %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %22
%36 = call i32 @time(i32 0)
store i32 %36, i32* %6
%37 = load i32*, i32** %7
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %7
%40 = call i8* @ctime(i32* %6)
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %7
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32*, i32** %7
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32*, i32** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0), i8* %49, i8* %52)
%54 = call i64 @cuserid(i32 0)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %9
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%57 = call i8* @ctime(i32* %6)
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
store i8* %59, i8** %16
br label %60
60: ; preds = %64, %35
%61 = load i8*, i8** %16
%62 = load i8, i8* %61
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i8*, i8** %16
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %16
br label %60
67: ; preds = %60
%68 = load i8*, i8** %16
%69 = getelementptr inbounds i8, i8* %68, i32 -1
store i8* %69, i8** %16
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br i1 %72, label %73, label %75
73: ; preds = %67
%74 = load i8*, i8** %16
store i8 0, i8* %74
br label %75
75: ; preds = %73, %67
%76 = load i32*, i32** %7
%77 = load i8*, i8** %9
%78 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %77, i8* %78)
%80 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [20 x i8] c"Couldn't create %s\0A\00"
@.str.3 = [4 x i8] c"/*\0A\00"
@.str.4 = [24 x i8] c" * G2 Version Stamp, %s\00"
@.str.5 = [55 x i8] c" * Automatically generated, hand edits are pointless.\0A\00"
@.str.6 = [6 x i8] c" */\0A\0A\00"
@.str.7 = [58 x i8] c"const char *version_string = \22G2 (%s) major version %s\22;\0A\00"
@.str.8 = [51 x i8] c"const char *minor_v_string = \22Built by %s at %s\22;\0A\00"
@str = [43 x i8] c"usage: mkversion ostype version outputfile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = tail call i32 @time(i32 0)
store i32 %21, i32* %3
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %14)
%23 = call i8* @ctime(i32* %3)
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = call i64 @fwrite(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i64 54, i64 1, i32* %14)
%26 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 5, i64 1, i32* %14)
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0), i8* %28, i8* %30)
%32 = call i64 @cuserid(i32 0)
%33 = call i8* @ctime(i32* %3)
%34 = call i32 @strcpy(i8* %6, i8* %33)
br label %35
35: ; preds = %35, %20
%36 = phi i8* [ %6, %20 ], [ %39, %35 ]
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
%39 = getelementptr inbounds i8, i8* %36, i64 1
br i1 %38, label %40, label %35
40: ; preds = %35
%41 = getelementptr inbounds i8, i8* %36, i64 -1
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 10
br i1 %43, label %44, label %45
44: ; preds = %40
store i8 0, i8* %41
br label %45
45: ; preds = %44, %40
%46 = inttoptr i64 %32 to i8*
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %46, i8* %6)
%48 = call i32 @exit(i32 0)
unreachable
}