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

/* Variables and functions */
int /*<<< orphan*/ fatal_error(int /*<<< orphan*/, char *, int, char *);
scalar_t__ fexist(char *);
char *gmx_strdup(char *);
int /*<<< orphan*/ save_free(char *, char *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int);
int strlen(char *);
char *backup_fn(char *file) {
  int i, count = 1;
  char *directory, *fn;
  static char buf[256];
  for (i = strlen(file) - 1; ((i > 0) && (file[i] != '/')); i--)
    ;
  if (i > 0) {
    directory = gmx_strdup(file);
    directory[i] = '\0';
    fn = gmx_strdup(file + i + 1);
  } else {
    directory = gmx_strdup(".");
    fn = gmx_strdup(file);
  }
  do {
    sprintf(buf, "%s/#%s.%d#", directory, fn, count);
    count++;
  } while ((count < 128) && fexist(buf));
  if (count == 128)
    fatal_error(0, "Won't make more than %d backups of %s for you", 128, fn);
  save_free("directory",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Chadi-akel/cere/refs/heads/master/tests/"
            "test_07/futil.c",
            266, (directory));
  save_free("fn",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Chadi-akel/cere/refs/heads/master/tests/"
            "test_07/futil.c",
            267, (fn));
  return buf;
}


x86 assembly (clang, -O0):
<backup_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jle    11a6 <backup_fn+0x46>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b6 <backup_fn+0x56>
jmp    11c9 <backup_fn+0x69>
jmp    11bb <backup_fn+0x5b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <backup_fn+0x22>
cmpl   $0x0,-0xc(%rbp)
jle    1209 <backup_fn+0xa9>
mov    -0x8(%rbp),%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    1226 <backup_fn+0xc6>
lea    0xdf0(%rip),%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    122b <backup_fn+0xcb>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8d
lea    0x2e22(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x80,-0x10(%rbp)
mov    %al,-0x22(%rbp)
jge    127b <backup_fn+0x11b>
lea    0x2df4(%rip),%rdi
call   1030 <fexist@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    122b <backup_fn+0xcb>
cmpl   $0x80,-0x10(%rbp)
jne    12aa <backup_fn+0x14a>
mov    -0x20(%rbp),%rcx
xor    %edi,%edi
lea    0xd6d(%rip),%rsi
mov    $0x80,%edx
call   1060 <fatal_error@plt>
mov    -0x18(%rbp),%rcx
lea    0xd86(%rip),%rdi
lea    0xd89(%rip),%rsi
mov    $0x10a,%edx
call   1070 <save_free@plt>
mov    -0x20(%rbp),%rcx
lea    0xe06(%rip),%rdi
lea    0xd6d(%rip),%rsi
mov    $0x10b,%edx
call   1070 <save_free@plt>
lea    0x2d77(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_fn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %eax,%eax
add    $0xffffffff,%ebx
add    $0x2,%rbx
nopl   0x0(%rax,%rax,1)
cmp    $0x2,%eax
jl     11aa <backup_fn+0x4a>
add    $0xffffffffffffffff,%rbx
cmpb   $0x2f,-0x1(%r15,%rax,1)
lea    -0x1(%rax),%rax
jne    1180 <backup_fn+0x20>
mov    %r15,%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,%r14
movb   $0x0,-0x1(%rax,%rbx,1)
add    %rbx,%r15
jmp    11b9 <backup_fn+0x59>
lea    0xe4f(%rip),%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <gmx_strdup@plt>
mov    %rax,%r15
mov    $0x1,%ebp
lea    0x2e90(%rip),%rbx
lea    0xe2b(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %ebp,%r8d
call   1080 <sprintf@plt>
cmp    $0x7f,%ebp
je     120b <backup_fn+0xab>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <fexist@plt>
test   %rax,%rax
jne    11e0 <backup_fn+0x80>
jmp    1221 <backup_fn+0xc1>
lea    0xdfb(%rip),%rsi
xor    %edi,%edi
mov    $0x80,%edx
mov    %r15,%rcx
call   1060 <fatal_error@plt>
lea    0xe13(%rip),%rdi
lea    0xe16(%rip),%rbx
mov    %rbx,%rsi
mov    $0x10a,%edx
mov    %r14,%rcx
call   1070 <save_free@plt>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
mov    $0x10b,%edx
mov    %r15,%rcx
call   1070 <save_free@plt>
lea    0x2e03(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@backup_fn.buf = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"%s/#%s.%d#\00"
@.str.2 = [46 x i8] c"Won't make more than %d backups of %s for you\00"
@.str.3 = [10 x i8] c"directory\00"
@.str.4 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Chadi-akel/cere/refs/heads/master/tests/test_07/futil.c\00"
@.str.5 = [3 x i8] c"fn\00"
define i8* @backup_fn(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %3
br label %10
10: ; preds = %24, %1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 47
br label %21
21: ; preds = %13, %10
%22 = phi i1 [ false, %10 ], [ %20, %13 ]
br i1 %22, label %23, label %27
23: ; preds = %21
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
br label %10
27: ; preds = %21
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = call i8* @gmx_strdup(i8* %31)
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %2
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i8* @gmx_strdup(i8* %41)
store i8* %42, i8** %6
br label %47
43: ; preds = %27
%44 = call i8* @gmx_strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %44, i8** %5
%45 = load i8*, i8** %2
%46 = call i8* @gmx_strdup(i8* %45)
store i8* %46, i8** %6
br label %47
47: ; preds = %43, %30
br label %48
48: ; preds = %61, %47
%49 = load i8*, i8** %5
%50 = load i8*, i8** %6
%51 = load i32, i32* %4
%52 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %49, i8* %50, i32 %51)
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %55
55: ; preds = %48
%56 = load i32, i32* %4
%57 = icmp slt i32 %56, 128
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = call i64 @fexist(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0))
%60 = icmp ne i64 %59, 0
br label %61
61: ; preds = %58, %55
%62 = phi i1 [ false, %55 ], [ %60, %58 ]
br i1 %62, label %48, label %63
63: ; preds = %61
%64 = load i32, i32* %4
%65 = icmp eq i32 %64, 128
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i8*, i8** %6
%68 = call i32 @fatal_error(i32 0, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 128, i8* %67)
br label %69
69: ; preds = %66, %63
%70 = load i8*, i8** %5
%71 = call i32 @save_free(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.4, i64 0, i64 0), i32 266, i8* %70)
%72 = load i8*, i8** %6
%73 = call i32 @save_free(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.4, i64 0, i64 0), i32 267, i8* %72)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@backup_fn.buf = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"%s/#%s.%d#\00"
@.str.2 = [46 x i8] c"Won't make more than %d backups of %s for you\00"
@.str.3 = [10 x i8] c"directory\00"
@.str.4 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Chadi-akel/cere/refs/heads/master/tests/test_07/futil.c\00"
@.str.5 = [3 x i8] c"fn\00"
define i8* @backup_fn(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %9, %1
%5 = phi i64 [ %6, %9 ], [ %3, %1 ]
%6 = add nsw i64 %5, -1
%7 = trunc i64 %5 to i32
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %20
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %4
13: ; preds = %9
%14 = and i64 %6, 4294967295
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i8* @gmx_strdup(i8* %0)
%17 = getelementptr inbounds i8, i8* %16, i64 %14
store i8 0, i8* %17
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = tail call i8* @gmx_strdup(i8* %18)
br label %23
20: ; preds = %4
%21 = tail call i8* @gmx_strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = tail call i8* @gmx_strdup(i8* %0)
br label %23
23: ; preds = %20, %13
%24 = phi i8* [ %16, %13 ], [ %21, %20 ]
%25 = phi i8* [ %19, %13 ], [ %22, %20 ]
br label %26
26: ; preds = %30, %23
%27 = phi i32 [ 1, %23 ], [ %31, %30 ]
%28 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25, i32 %27)
%29 = icmp eq i32 %27, 127
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = add nuw nsw i32 %27, 1
%32 = tail call i64 @fexist(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %26
34: ; preds = %26
%35 = tail call i32 @fatal_error(i32 0, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 128, i8* %25)
br label %36
36: ; preds = %30, %34
%37 = tail call i32 @save_free(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.4, i64 0, i64 0), i32 266, i8* %24)
%38 = tail call i32 @save_free(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.4, i64 0, i64 0), i32 267, i8* %25)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @backup_fn.buf, i64 0, i64 0)
}