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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fatal(char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *format_build_date(struct tm *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_linker_timestamp(int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *file;
  time_t timestamp;
  struct tm *utc;
  char *formatted;
  if (argc < 2 || strcmp(argv[1], "--help") == 0) {
    print_help();
    return EXIT_SUCCESS;
  }
  file = fopen(argv[1], "r");
  if (!file) {
    fatal("Couldn't open file '%s'.", argv[1]);
  }
  timestamp = get_linker_timestamp(file);
  fclose(file);
  utc = gmtime(&timestamp);
  if (utc == NULL) {
    fatal("Failed to identify a timestamp.");
  }
  formatted = format_build_date(utc);
  printf("Build date: %s\n", formatted);
  free(formatted);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11de <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f6 <main+0x56>
mov    $0x0,%al
call   10a0 <print_help@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    129c <main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe02(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122f <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   10c0 <fatal@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <get_linker_timestamp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <gmtime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126a <main+0xca>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   10c0 <fatal@plt>
mov    -0x28(%rbp),%rdi
call   1080 <format_build_date@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     124b <main+0xab>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe45(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     124b <main+0xab>
mov    0x8(%rbx),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11f3 <main+0x53>
mov    0x8(%rbx),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   10c0 <fatal@plt>
mov    %r14,%rdi
call   10b0 <get_linker_timestamp@plt>
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x4(%rsp),%rdi
call   1090 <gmtime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <main+0x87>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   10c0 <fatal@plt>
mov    %rbx,%rdi
call   1080 <format_build_date@plt>
mov    %rax,%rbx
lea    0xe09(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1252 <main+0xb2>
xor    %eax,%eax
call   10a0 <print_help@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Couldn't open file '%s'.\00"
@.str.3 = [32 x i8] c"Failed to identify a timestamp.\00"
@.str.4 = [16 x i8] c"Build date: %s\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 %struct.tm*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12, %2
%19 = call i32 (...) @print_help()
%20 = load i32, i32* @EXIT_SUCCESS
store i32 %20, i32* %3
br label %51
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %21
%34 = load i32*, i32** %6
%35 = call i32 @get_linker_timestamp(i32* %34)
store i32 %35, i32* %7
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = call %struct.tm* @gmtime(i32* %7)
store %struct.tm* %38, %struct.tm** %8
%39 = load %struct.tm*, %struct.tm** %8
%40 = icmp eq %struct.tm* %39, null
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %33
%44 = load %struct.tm*, %struct.tm** %8
%45 = call i8* @format_build_date(%struct.tm* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %9
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %3
br label %51
51: ; preds = %43, %18
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Couldn't open file '%s'.\00"
@.str.3 = [32 x i8] c"Failed to identify a timestamp.\00"
@.str.4 = [16 x i8] c"Build date: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6, %2
%12 = tail call i32 (...) @print_help()
br label %31
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %13
%21 = tail call i32 @get_linker_timestamp(i32* %15)
store i32 %21, i32* %3
%22 = tail call i32 @fclose(i32* %15)
%23 = call %struct.tm* @gmtime(i32* %3)
%24 = icmp eq %struct.tm* %23, null
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = call i8* @format_build_date(%struct.tm* %23)
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = call i32 @free(i8* %28)
br label %31
31: ; preds = %27, %11
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}