#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;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ printf(char *, int);
int revert_version(char *, char *, int);
int revert_version_by_time(char *, char *, scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  time_t time;
  int version;
  int argp = 1, ret = 0;
  char *file = NULL;
  char revert_file[1024];
  if (argc < 3)
    usage();
  if (strcmp(argv[argp], "-a") == 0) {
    file = argv[argp + 1];
    for (version = 1;; version++) {
      sprintf(revert_file, "%s.%d", file, version);
      ret = revert_version(file, revert_file, version);
      if (!ret)
        break;
    }
  } else if (strcmp(argv[argp], "-t") == 0) {
    time = (time_t)atoi(argv[argp + 1]);
    file = argv[argp + 2];
    sprintf(revert_file, "%s@%d", file, (int)time);
    ret = revert_version_by_time(file, revert_file, time);
    if (!ret)
      printf("Unable to find version at %d\n", (int)time);
  } else {
    version = atoi(argv[argp]);
    file = argv[argp + 1];
    sprintf(revert_file, "%s.%d", file, version);
    ret = revert_version(file, revert_file, version);
    if (!ret)
      printf("Unable to find version %d\n", version);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b0 <main+0x40>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe3d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1245 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe00(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <revert_version@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    122d <main+0xbd>
jmp    1240 <main+0xd0>
jmp    1232 <main+0xc2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ee <main+0x7e>
jmp    1369 <main+0x1f9>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdb1(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12ed <main+0x17d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
lea    0xd5c(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <revert_version_by_time@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12e8 <main+0x178>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xd2f(%rip),%rdi
call   1030 <printf@plt>
jmp    1364 <main+0x1f4>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xcd8(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <revert_version@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    135f <main+0x1ef>
mov    -0x1c(%rbp),%esi
lea    0xcd6(%rip),%rdi
call   1030 <printf@plt>
jmp    1364 <main+0x1f4>
jmp    1369 <main+0x1f9>
mov    -0x24(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     118c <main+0x1c>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe69(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1201 <main+0x91>
mov    0x8(%rbx),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1246 <main+0xd6>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rbx
lea    0xe33(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <revert_version@plt>
test   %eax,%eax
jne    1291 <main+0x121>
lea    0xe34(%rip),%rdi
jmp    1288 <main+0x118>
mov    0x10(%rbx),%rbx
mov    $0x1,%ebp
lea    0xdf2(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <revert_version@plt>
add    $0x1,%ebp
test   %eax,%eax
jne    1220 <main+0xb0>
jmp    128f <main+0x11f>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
movslq %eax,%r14
mov    0x18(%rbx),%rbx
lea    0xdad(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <revert_version_by_time@plt>
test   %eax,%eax
jne    1291 <main+0x121>
lea    0xd8a(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-a\00"
@.str.1 = [6 x i8] c"%s.%d\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [6 x i8] c"%s@%d\00"
@.str.4 = [30 x i8] c"Unable to find version at %d\0A\00"
@.str.5 = [27 x i8] c"Unable to find version %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %10
store i32 1, i32* %7
br label %31
31: ; preds = %44, %24
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%33 = load i8*, i8** %10
%34 = load i32, i32* %7
%35 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %34)
%36 = load i8*, i8** %10
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @revert_version(i8* %36, i8* %37, i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %31
br label %47
43: ; preds = %31
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %31
47: ; preds = %42
br label %115
48: ; preds = %16
%49 = load i8**, i8*** %5
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %87
56: ; preds = %48
%57 = load i8**, i8*** %5
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @atoi(i8* %62)
%64 = sext i32 %63 to i64
store i64 %64, i64* %6
%65 = load i8**, i8*** %5
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 2
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %65, i64 %68
%70 = load i8*, i8** %69
store i8* %70, i8** %10
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%72 = load i8*, i8** %10
%73 = load i64, i64* %6
%74 = trunc i64 %73 to i32
%75 = call i32 @sprintf(i8* %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %72, i32 %74)
%76 = load i8*, i8** %10
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%78 = load i64, i64* %6
%79 = call i32 @revert_version_by_time(i8* %76, i8* %77, i64 %78)
store i32 %79, i32* %9
%80 = load i32, i32* %9
%81 = icmp ne i32 %80, 0
br i1 %81, label %86, label %82
82: ; preds = %56
%83 = load i64, i64* %6
%84 = trunc i64 %83 to i32
%85 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %82, %56
br label %114
87: ; preds = %48
%88 = load i8**, i8*** %5
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8*, i8** %88, i64 %90
%92 = load i8*, i8** %91
%93 = call i32 @atoi(i8* %92)
store i32 %93, i32* %7
%94 = load i8**, i8*** %5
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
store i8* %99, i8** %10
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%101 = load i8*, i8** %10
%102 = load i32, i32* %7
%103 = call i32 @sprintf(i8* %100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %101, i32 %102)
%104 = load i8*, i8** %10
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%106 = load i32, i32* %7
%107 = call i32 @revert_version(i8* %104, i8* %105, i32 %106)
store i32 %107, i32* %9
%108 = load i32, i32* %9
%109 = icmp ne i32 %108, 0
br i1 %109, label %113, label %110
110: ; preds = %87
%111 = load i32, i32* %7
%112 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %111)
br label %113
113: ; preds = %110, %87
br label %114
114: ; preds = %113, %86
br label %115
115: ; preds = %114, %47
%116 = load i32, i32* %9
ret i32 %116
}

LLVM IR (-O2):
@.str = [3 x i8] c"-a\00"
@.str.1 = [6 x i8] c"%s.%d\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [6 x i8] c"%s@%d\00"
@.str.4 = [30 x i8] c"Unable to find version at %d\0A\00"
@.str.5 = [27 x i8] c"Unable to find version %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
br label %16
16: ; preds = %16, %13
%17 = phi i32 [ 1, %13 ], [ %21, %16 ]
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %17)
%19 = call i32 @revert_version(i8* %15, i8* %4, i32 %17)
%20 = icmp eq i32 %19, 0
%21 = add nuw nsw i32 %17, 1
br i1 %20, label %48, label %16
22: ; preds = %8
%23 = load i8*, i8** %9
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %32, i32 %29)
%34 = call i32 @revert_version_by_time(i8* %32, i8* %4, i64 %30)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %26
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %48
38: ; preds = %22
%39 = load i8*, i8** %9
%40 = tail call i32 @atoi(i8* %39)
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %42, i32 %40)
%44 = call i32 @revert_version(i8* %42, i8* %4, i32 %40)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %40)
br label %48
48: ; preds = %16, %36, %26, %46, %38
%49 = phi i32 [ %34, %26 ], [ 0, %36 ], [ %44, %38 ], [ 0, %46 ], [ 0, %16 ]
ret i32 %49
}