#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ PhotoTimeFormat;
typedef int /*<<< orphan*/ GPSTimeFormat;
typedef int /*<<< orphan*/ CombinedTime;

/* Variables and functions */
scalar_t__ ConvertToUnixTime(char *, char *, int, int);
char *ReadGPSTimestamp(char const *, char *, char *, int *);
int WriteFixedDatestamp(char const *, scalar_t__);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gmtime(scalar_t__ *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int FixDatestamp(const char *File, int AdjustmentHours, int AdjustmentMinutes,
                 int NoWriteExif) {
  char DateStamp[12];
  char TimeStamp[12];
  char CombinedTime[24];
  int IncludesGPS = 0;
  char *OriginalDateStamp = NULL;
  int rc = 1;
  OriginalDateStamp =
      ReadGPSTimestamp(File, DateStamp, TimeStamp, &IncludesGPS);
  if (OriginalDateStamp == NULL) {
    printf(("%s: No EXIF data.\n"), File);
    rc = 0;
  } else if (IncludesGPS == 0) {
    printf(("%s: No GPS data.\n"), File);
    rc = 0;
  } else {
    time_t PhotoTime = ConvertToUnixTime(OriginalDateStamp, "%d:%d:%d %d:%d:%d",
                                         AdjustmentHours, AdjustmentMinutes);
    snprintf(CombinedTime, sizeof(CombinedTime), "%s %s", DateStamp, TimeStamp);
    time_t GPSTime = ConvertToUnixTime(CombinedTime, "%d:%d:%d %d:%d:%d", 0, 0);
    if (PhotoTime != GPSTime) {
      if (!NoWriteExif) {
        rc = WriteFixedDatestamp(File, PhotoTime);
      }
      char PhotoTimeFormat[100];
      char GPSTimeFormat[100];
      strftime(PhotoTimeFormat, sizeof(PhotoTimeFormat), "%a %b %e %T %Y UTC",
               gmtime(&PhotoTime));
      strftime(GPSTimeFormat, sizeof(GPSTimeFormat), "%a %b %e %T %Y UTC",
               gmtime(&GPSTime));
      printf(("%s: Wrong timestamp:\n   Photo:     %s\n"
              "   GPS:       %s\n   Corrected: %s\n"),
             File, PhotoTimeFormat, GPSTimeFormat, PhotoTimeFormat);
    } else {
      printf(("%s: Timestamp is OK: Photo %s (localtime), GPS %s (UTC).\n"),
             File, OriginalDateStamp, CombinedTime);
    }
  }
  free(OriginalDateStamp);
  return rc;
}


x86 assembly (clang, -O0):
<FixDatestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x54(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x54(%rbp),%rcx
call   1050 <ReadGPSTimestamp@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    11f0 <FixDatestamp+0x70>
mov    -0x8(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x64(%rbp)
jmp    1341 <FixDatestamp+0x1c1>
cmpl   $0x0,-0x54(%rbp)
jne    1218 <FixDatestamp+0x98>
mov    -0x8(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x64(%rbp)
jmp    133c <FixDatestamp+0x1bc>
mov    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdfc(%rip),%rsi
call   1080 <ConvertToUnixTime@plt>
mov    %rax,-0x70(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x18,%esi
lea    0xded(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xdcb(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1080 <ConvertToUnixTime@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x78(%rbp),%rax
je     131d <FixDatestamp+0x19d>
cmpl   $0x0,-0x14(%rbp)
jne    128f <FixDatestamp+0x10f>
mov    -0x8(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1040 <WriteFixedDatestamp@plt>
mov    %eax,-0x64(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x70(%rbp),%rdi
call   10a0 <gmtime@plt>
mov    -0x160(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xd82(%rip),%rdx
call   1090 <strftime@plt>
lea    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x78(%rbp),%rdi
call   10a0 <gmtime@plt>
mov    -0x158(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xd51(%rip),%rdx
call   1090 <strftime@plt>
mov    -0x8(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
lea    -0x150(%rbp),%rcx
lea    -0xe0(%rbp),%r8
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1337 <FixDatestamp+0x1b7>
mov    -0x8(%rbp),%rsi
mov    -0x60(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    133c <FixDatestamp+0x1bc>
jmp    1341 <FixDatestamp+0x1c1>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FixDatestamp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
lea    0x24(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <ReadGPSTimestamp@plt>
mov    %rax,%r13
test   %rax,%rax
je     124c <FixDatestamp+0xcc>
cmpl   $0x0,0x4(%rsp)
je     1255 <FixDatestamp+0xd5>
lea    0xe50(%rip),%r12
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1080 <ConvertToUnixTime@plt>
mov    %rax,%rbp
mov    %rax,0x10(%rsp)
lea    0xe44(%rip),%rdx
lea    0x30(%rsp),%rbx
lea    0x24(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %rbx,%rdi
mov    $0x18,%esi
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <ConvertToUnixTime@plt>
mov    %rax,0x8(%rsp)
cmp    %rax,%rbp
jne    126b <FixDatestamp+0xeb>
lea    0xe6a(%rip),%rdi
lea    0x30(%rsp),%rcx
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r12d
jmp    12ea <FixDatestamp+0x16a>
lea    0xdad(%rip),%rdi
jmp    125c <FixDatestamp+0xdc>
lea    0xdb7(%rip),%rdi
xor    %r12d,%r12d
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ea <FixDatestamp+0x16a>
mov    $0x1,%r12d
test   %r15d,%r15d
jne    1284 <FixDatestamp+0x104>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <WriteFixedDatestamp@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
call   10a0 <gmtime@plt>
lea    0xda8(%rip),%r15
lea    0xc0(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1090 <strftime@plt>
lea    0x8(%rsp),%rdi
call   10a0 <gmtime@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1090 <strftime@plt>
lea    0xd79(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%s: No EXIF data.\0A\00"
@.str.1 = [18 x i8] c"%s: No GPS data.\0A\00"
@.str.2 = [18 x i8] c"%d:%d:%d %d:%d:%d\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.4 = [19 x i8] c"%a %b %e %T %Y UTC\00"
@.str.5 = [73 x i8] c"%s: Wrong timestamp:\0A Photo: %s\0A GPS: %s\0A Corrected: %s\0A\00"
@.str.6 = [58 x i8] c"%s: Timestamp is OK: Photo %s (localtime), GPS %s (UTC).\0A\00"
define i32 @FixDatestamp(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [12 x i8]
%10 = alloca [12 x i8]
%11 = alloca [24 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca [100 x i8]
%18 = alloca [100 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %12
store i8* null, i8** %13
store i32 1, i32* %14
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%22 = call i8* @ReadGPSTimestamp(i8* %19, i8* %20, i8* %21, i32* %12)
store i8* %22, i8** %13
%23 = load i8*, i8** %13
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %4
%26 = load i8*, i8** %5
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 0, i32* %14
br label %74
28: ; preds = %4
%29 = load i32, i32* %12
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 0, i32* %14
br label %73
34: ; preds = %28
%35 = load i8*, i8** %13
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = call i64 @ConvertToUnixTime(i8* %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
store i64 %38, i64* %15
%39 = getelementptr inbounds [24 x i8], [24 x i8]* %11, i64 0, i64 0
%40 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%42 = call i32 @snprintf(i8* %39, i32 24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41)
%43 = getelementptr inbounds [24 x i8], [24 x i8]* %11, i64 0, i64 0
%44 = call i64 @ConvertToUnixTime(i8* %43, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
store i64 %44, i64* %16
%45 = load i64, i64* %15
%46 = load i64, i64* %16
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %67
48: ; preds = %34
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i8*, i8** %5
%53 = load i64, i64* %15
%54 = call i32 @WriteFixedDatestamp(i8* %52, i64 %53)
store i32 %54, i32* %14
br label %55
55: ; preds = %51, %48
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i64 0, i64 0
%57 = call i32 @gmtime(i64* %15)
%58 = call i32 @strftime(i8* %56, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%60 = call i32 @gmtime(i64* %16)
%61 = call i32 @strftime(i8* %59, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %60)
%62 = load i8*, i8** %5
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i64 0, i64 0
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i64 0, i64 0
%66 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0), i8* %62, i8* %63, i8* %64, i8* %65)
br label %72
67: ; preds = %34
%68 = load i8*, i8** %5
%69 = load i8*, i8** %13
%70 = getelementptr inbounds [24 x i8], [24 x i8]* %11, i64 0, i64 0
%71 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0), i8* %68, i8* %69, i8* %70)
br label %72
72: ; preds = %67, %55
br label %73
73: ; preds = %72, %31
br label %74
74: ; preds = %73, %25
%75 = load i8*, i8** %13
%76 = call i32 @free(i8* %75)
%77 = load i32, i32* %14
ret i32 %77
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s: No EXIF data.\0A\00"
@.str.1 = [18 x i8] c"%s: No GPS data.\0A\00"
@.str.2 = [18 x i8] c"%d:%d:%d %d:%d:%d\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.4 = [19 x i8] c"%a %b %e %T %Y UTC\00"
@.str.5 = [73 x i8] c"%s: Wrong timestamp:\0A Photo: %s\0A GPS: %s\0A Corrected: %s\0A\00"
@.str.6 = [58 x i8] c"%s: Timestamp is OK: Photo %s (localtime), GPS %s (UTC).\0A\00"
define i32 @FixDatestamp(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [12 x i8]
%6 = alloca [12 x i8]
%7 = alloca [24 x i8]
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca [100 x i8]
%12 = alloca [100 x i8]
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%16 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%17 = call i8* @ReadGPSTimestamp(i8* %0, i8* %13, i8* %14, i32* %8)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %50
21: ; preds = %4
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %50
26: ; preds = %21
%27 = bitcast i64* %9 to i8*
%28 = call i64 @ConvertToUnixTime(i8* %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %2)
store i64 %28, i64* %9
%29 = call i32 @snprintf(i8* %15, i32 24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %14)
%30 = bitcast i64* %10 to i8*
%31 = call i64 @ConvertToUnixTime(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
store i64 %31, i64* %10
%32 = icmp eq i64 %28, %31
br i1 %32, label %46, label %33
33: ; preds = %26
%34 = icmp eq i32 %3, 0
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = call i32 @WriteFixedDatestamp(i8* %0, i64 %28)
br label %37
37: ; preds = %35, %33
%38 = phi i32 [ 1, %33 ], [ %36, %35 ]
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%41 = call i32 @gmtime(i64* %9)
%42 = call i32 @strftime(i8* %39, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = call i32 @gmtime(i64* %10)
%44 = call i32 @strftime(i8* %40, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %39, i8* %40, i8* %39)
br label %48
46: ; preds = %26
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %17, i8* %15)
br label %48
48: ; preds = %46, %37
%49 = phi i32 [ %38, %37 ], [ 1, %46 ]
br label %50
50: ; preds = %24, %48, %19
%51 = phi i32 [ 0, %19 ], [ 0, %24 ], [ %49, %48 ]
%52 = call i32 @free(i8* %17)
ret i32 %51
}