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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ current_ymd(int *, int *, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int main(void) {
  int yb = 0, mb = 0, db = 0;
  int y = 0, m = 0, d = 0;
  int n, update = 1;
  char *s, line[128];
  FILE *fp;
  current_ymd(&y, &m, &d);
  fp = fopen("build.h", "r");
  if (fp != NULL) {
    if (fgets(line, sizeof line, fp) != NULL) {
      s = strstr(line, "20");
      if (s != NULL) {
        n = sscanf(s, "%d-%d-%d", &yb, &mb, &db);
        if (n == 3 && y == yb && m == mb && d == db) {
          update = 0;
        }
      }
    }
    fclose(fp);
  }
  if (update) {
    fp = fopen("build.h", "w");
    if (fp == NULL) {
      fprintf(stderr, "Can't write to build.h\n");
      exit(EXIT_FAILURE);
    } else {
      printf("Updating build.h\n");
      fprintf(fp, "#define BUILD_DATE \"%d-%02d-%02d\"\n", y, m, d);
      fclose(fp);
    }
  } else {
    printf("build.h is current\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <current_ymd@plt>
lea    0xe15(%rip),%rdi
lea    0xe16(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
je     12ba <main+0x12a>
lea    -0xb0(%rbp),%rdi
mov    -0xb8(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ae <main+0x11e>
lea    -0xb0(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12a9 <main+0x119>
mov    -0x30(%rbp),%rdi
lea    0xdb2(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1070 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jne    12a4 <main+0x114>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    12a4 <main+0x114>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    12a4 <main+0x114>
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    12a4 <main+0x114>
movl   $0x0,-0x24(%rbp)
jmp    12a9 <main+0x119>
jmp    12ae <main+0x11e>
mov    -0xb8(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
je     134e <main+0x1be>
lea    0xd35(%rip),%rdi
lea    0xd44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    1312 <main+0x182>
mov    0x2ced(%rip),%rax
movslq (%rax),%rdi
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd17(%rip),%rdi
call   1040 <printf@plt>
mov    -0xb8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xb8(%rbp),%rdi
call   1030 <fclose@plt>
jmp    135a <main+0x1ca>
lea    0xd10(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xa0,%rsp
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1080 <current_ymd@plt>
lea    0xe74(%rip),%rdi
lea    0xe06(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1297 <main+0xf7>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     128f <main+0xef>
lea    0xdd9(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10c0 <strstr@plt>
test   %rax,%rax
je     128f <main+0xef>
lea    0xdc6(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
mov    %rax,%rdi
call   1070 <sscanf@plt>
cmp    $0x3,%eax
jne    128f <main+0xef>
mov    0x10(%rsp),%eax
cmp    0x1c(%rsp),%eax
jne    128f <main+0xef>
mov    0xc(%rsp),%eax
cmp    0x18(%rsp),%eax
jne    128f <main+0xef>
mov    0x8(%rsp),%eax
cmp    0x14(%rsp),%eax
jne    128f <main+0xef>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdc3(%rip),%rdi
call   1030 <puts@plt>
jmp    12e4 <main+0x144>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdc9(%rip),%rdi
lea    0xd69(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ef <main+0x14f>
mov    %rax,%rbx
lea    0xda5(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xd56(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
ret
mov    0x2cea(%rip),%rax
movslq (%rax),%rcx
lea    0xd10(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"build.h\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"20\00"
@.str.3 = [9 x i8] c"%d-%d-%d\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [24 x i8] c"Can't write to build.h\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [18 x i8] c"Updating build.h\0A\00"
@.str.7 = [35 x i8] c"#define BUILD_DATE \22%d-%02d-%02d\22\0A\00"
@.str.8 = [20 x i8] c"build.h is current\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [128 x i8]
%12 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %9
%13 = call i32 @current_ymd(i32* %5, i32* %6, i32* %7)
%14 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %50
17: ; preds = %0
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%19 = load i32*, i32** %12
%20 = call i32* @fgets(i8* %18, i32 128, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %47
22: ; preds = %17
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %46
27: ; preds = %22
%28 = load i8*, i8** %10
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load i32, i32* %5
%34 = load i32, i32* %2
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32, i32* %6
%38 = load i32, i32* %3
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* %7
%42 = load i32, i32* %4
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 0, i32* %9
br label %45
45: ; preds = %44, %40, %36, %32, %27
br label %46
46: ; preds = %45, %22
br label %47
47: ; preds = %46, %17
%48 = load i32*, i32** %12
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %47, %0
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %74
53: ; preds = %50
%54 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %54, i32** %12
%55 = load i32*, i32** %12
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %64
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = sext i32 %58 to i64
%60 = inttoptr i64 %59 to i32*
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %53
%65 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%66 = load i32*, i32** %12
%67 = load i32, i32* %5
%68 = load i32, i32* %6
%69 = load i32, i32* %7
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %67, i32 %68, i32 %69)
%71 = load i32*, i32** %12
%72 = call i32 @fclose(i32* %71)
br label %73
73: ; preds = %64
br label %76
74: ; preds = %50
%75 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %74, %73
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"build.h\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"20\00"
@.str.3 = [9 x i8] c"%d-%d-%d\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [24 x i8] c"Can't write to build.h\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [35 x i8] c"#define BUILD_DATE \22%d-%02d-%02d\22\0A\00"
@str = [19 x i8] c"build.h is current\00"
@str.9 = [17 x i8] c"Updating build.h\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%9 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%13 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%15 = call i32 @current_ymd(i32* %4, i32* %5, i32* %6)
%16 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %41, label %18
18: ; preds = %0
%19 = call i32* @fgets(i8* %14, i32 128, i32* %16)
%20 = icmp eq i32* %19, null
br i1 %20, label %39, label %21
21: ; preds = %18
%22 = call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %39, label %24
24: ; preds = %21
%25 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i32, i32* %4
%29 = load i32, i32* %1
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i32, i32* %5
%33 = load i32, i32* %2
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %6
%37 = load i32, i32* %3
%38 = icmp eq i32 %36, %37
br i1 %38, label %58, label %39
39: ; preds = %31, %27, %24, %21, %18, %35
%40 = call i32 @fclose(i32* %16)
br label %41
41: ; preds = %0, %39
%42 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i32*
%48 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 23, i64 1, i32* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %41
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %53, i32 %54, i32 %55)
%57 = call i32 @fclose(i32* %42)
br label %61
58: ; preds = %35
%59 = call i32 @fclose(i32* %16)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %61
61: ; preds = %58, %51
ret i32 0
}