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

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
int /*<<< orphan*/ test_save_compatibility(char *);
int main(int argc, char *argv[]) {
  char base_path[4096];
  if (argc <= 1) {
    const char *srcdir = getenv("srcdir");
    if (srcdir == NULL) {
      srcdir = ".";
    }
    strcpy(base_path, srcdir);
  } else {
    strcpy(base_path, argv[1]);
    base_path[strrchr(base_path, '/') - base_path] = 0;
  }
  char save_path[4096 + sizeof("../auto_tests/data/save.tox")];
  snprintf(save_path, sizeof(save_path), "%s/%s", base_path,
           "../auto_tests/data/save.tox");
  test_save_compatibility(save_path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11ba <main+0x6a>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    11a2 <main+0x52>
lea    0xe6c(%rip),%rax
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11f1 <main+0xa1>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    -0x1010(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x2040(%rbp),%rdi
lea    -0x1010(%rbp),%rcx
mov    $0x101c,%esi
lea    0xdfe(%rip),%rdx
lea    0xdfd(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1070 <test_save_compatibility@plt>
xor    %eax,%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2020,%rsp
cmp    $0x1,%edi
jg     1181 <main+0x31>
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe94(%rip),%rsi
cmovne %rax,%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
jmp    11a0 <main+0x50>
mov    0x8(%rsi),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
movb   $0x0,(%rax)
lea    0xe62(%rip),%rdx
lea    0xe61(%rip),%r8
lea    0x1000(%rsp),%rbx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    $0x101c,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <test_save_compatibility@plt>
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"srcdir\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [28 x i8] c"../auto_tests/data/save.tox\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca [4124 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %16
16: ; preds = %15, %11
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i32 @strcpy(i8* %17, i8* %18)
br label %33
20: ; preds = %2
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%27 = call i8* @strrchr(i8* %26, i8 signext 47)
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %20, %16
%34 = getelementptr inbounds [4124 x i8], [4124 x i8]* %8, i64 0, i64 0
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%36 = call i32 @snprintf(i8* %34, i32 4124, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [4124 x i8], [4124 x i8]* %8, i64 0, i64 0
%38 = call i32 @test_save_compatibility(i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"srcdir\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [28 x i8] c"../auto_tests/data/save.tox\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4124 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = call i32 @strcpy(i8* %5, i8* %10)
br label %21
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strcpy(i8* %5, i8* %14)
%16 = call i8* @strrchr(i8* %5, i8 signext 47)
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint [4096 x i8]* %3 to i64
%19 = sub i64 %17, %18
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %12, %7
%22 = getelementptr inbounds [4124 x i8], [4124 x i8]* %4, i64 0, i64 0
%23 = call i32 @snprintf(i8* %22, i32 4124, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @test_save_compatibility(i8* %22)
ret i32 0
}