#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 */
scalar_t__ GetDateTime(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ PrintUsage();
scalar_t__ SetStamp(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  time_t ltime;
  if (argc != 3) {
    PrintUsage();
    return -1;
  }
  fp = fopen(argv[2], "r+");
  if (fp == NULL) {
    return 0;
  }
  if (GetDateTime(fp, &ltime) != 0) {
    fclose(fp);
    return -1;
  }
  fclose(fp);
  fp = fopen(argv[1], "r+b");
  if (fp == NULL) {
    printf("Error: Cannot open the PE file!\n");
    return -1;
  }
  if (SetStamp(fp, ltime) != 0) {
    fclose(fp);
    return -1;
  }
  printf("Set Date/Time Stamp to %s", ctime(&ltime));
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a3 <main+0x33>
mov    $0x0,%al
call   1030 <PrintUsage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x129>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <main+0x62>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x129>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <GetDateTime@plt>
cmp    $0x0,%rax
je     11fe <main+0x8e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x129>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xded(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1244 <main+0xd4>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x129>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <SetStamp@plt>
cmp    $0x0,%rax
je     126f <main+0xff>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x129>
lea    -0x1c(%rbp),%rdi
call   1050 <ctime@plt>
mov    %rax,%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1222 <main+0xa2>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1230 <main+0xb0>
mov    %rax,%rbp
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   10a0 <GetDateTime@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%ebp
test   %r14,%r14
jne    1232 <main+0xb2>
mov    0x8(%rbx),%rdi
lea    0xe26(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123d <main+0xbd>
mov    %rax,%r14
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1080 <SetStamp@plt>
test   %rax,%rax
jne    1218 <main+0x98>
lea    0xc(%rsp),%rdi
call   1060 <ctime@plt>
lea    0xdfb(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1232 <main+0xb2>
xor    %eax,%eax
call   1040 <PrintUsage@plt>
mov    $0xffffffff,%ebp
jmp    1232 <main+0xb2>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
jmp    1232 <main+0xb2>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [33 x i8] c"Error: Cannot open the PE file!\0A\00"
@.str.3 = [26 x i8] c"Set Date/Time Stamp to %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @PrintUsage()
store i32 -1, i32* %3
br label %51
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 0, i32* %3
br label %51
20: ; preds = %12
%21 = load i32*, i32** %6
%22 = call i64 @GetDateTime(i32* %21, i32* %7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
store i32 -1, i32* %3
br label %51
27: ; preds = %20
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
38: ; preds = %27
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = call i64 @SetStamp(i32* %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
store i32 -1, i32* %3
br label %51
46: ; preds = %38
%47 = call i8* @ctime(i32* %7)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %46, %43, %36, %24, %19, %10
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.3 = [26 x i8] c"Set Date/Time Stamp to %s\00"
@str = [32 x i8] c"Error: Cannot open the PE file!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @PrintUsage()
br label %34
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %34, label %13
13: ; preds = %8
%14 = call i64 @GetDateTime(i32* %11, i32* %3)
%15 = icmp eq i64 %14, 0
%16 = call i32 @fclose(i32* %11)
br i1 %15, label %17, label %34
17: ; preds = %13
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %34
24: ; preds = %17
%25 = load i32, i32* %3
%26 = call i64 @SetStamp(i32* %20, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @fclose(i32* %20)
br label %34
30: ; preds = %24
%31 = call i8* @ctime(i32* %3)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = call i32 @fclose(i32* %20)
br label %34
34: ; preds = %13, %8, %30, %28, %22, %6
%35 = phi i32 [ -1, %6 ], [ -1, %22 ], [ -1, %28 ], [ 0, %30 ], [ 0, %8 ], [ -1, %13 ]
ret i32 %35
}