#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 */
struct statfs {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ DataManager_GetStrValue(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ statfs(char *, struct statfs *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ui_print(char *, ...);
int check_backup_name(int show_error) {
  char backup_name[64];
  char backup_loc[255], tw_image_dir[255];
  int copy_size = strlen(DataManager_GetStrValue("tw_backup_name"));
  int index, cur_char;
  struct statfs st;
  if (copy_size > 64) {
    if (show_error)
      ui_print("E:"
               "Backup name is too long.\n");
    return -2;
  }
  strncpy(backup_name, DataManager_GetStrValue("tw_backup_name"), copy_size);
  if (strcmp(backup_name, "0") == 0)
    return 0;
  for (index = 0; index < copy_size; index++) {
    cur_char = (int)backup_name[index];
    if ((cur_char >= 48 && cur_char <= 57) ||
        (cur_char >= 65 && cur_char <= 91) || cur_char == 93 ||
        cur_char == 95 || (cur_char >= 97 && cur_char <= 123) ||
        cur_char == 125 || cur_char == 45 || cur_char == 46) {
    } else {
      if (show_error)
        ui_print("E:"
                 "Backup name '%s' contains invalid character: '%c'\n",
                 backup_name, (char)cur_char);
      return -3;
    }
  }
  strcpy(backup_loc, DataManager_GetStrValue("tw_backups_folder"));
  sprintf(tw_image_dir, "%s/%s/.", backup_loc, backup_name);
  if (statfs(tw_image_dir, &st) == 0) {
    if (show_error)
      ui_print("E:"
               "A backup with this name already exists.\n");
    return -4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_backup_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe6b(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
mov    %eax,%edi
call   1050 <strlen@plt>
mov    %eax,-0x254(%rbp)
cmpl   $0x40,-0x254(%rbp)
jle    11d8 <check_backup_name+0x58>
cmpl   $0x0,-0x8(%rbp)
je     11cc <check_backup_name+0x4c>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1060 <ui_print@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13c3 <check_backup_name+0x243>
lea    -0x50(%rbp),%rax
mov    %rax,-0x268(%rbp)
lea    0xe16(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
mov    -0x268(%rbp),%rdi
mov    %eax,%esi
mov    -0x254(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1229 <check_backup_name+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    13c3 <check_backup_name+0x243>
movl   $0x0,-0x258(%rbp)
mov    -0x258(%rbp),%eax
cmp    -0x254(%rbp),%eax
jge    1335 <check_backup_name+0x1b5>
movslq -0x258(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
mov    %eax,-0x25c(%rbp)
cmpl   $0x30,-0x25c(%rbp)
jl     1271 <check_backup_name+0xf1>
cmpl   $0x39,-0x25c(%rbp)
jle    12e6 <check_backup_name+0x166>
cmpl   $0x41,-0x25c(%rbp)
jl     128b <check_backup_name+0x10b>
cmpl   $0x5b,-0x25c(%rbp)
jle    12e6 <check_backup_name+0x166>
cmpl   $0x5d,-0x25c(%rbp)
je     12e6 <check_backup_name+0x166>
cmpl   $0x5f,-0x25c(%rbp)
je     12e6 <check_backup_name+0x166>
cmpl   $0x61,-0x25c(%rbp)
jl     12bf <check_backup_name+0x13f>
cmpl   $0x7b,-0x25c(%rbp)
jle    12e6 <check_backup_name+0x166>
cmpl   $0x7d,-0x25c(%rbp)
je     12e6 <check_backup_name+0x166>
cmpl   $0x2d,-0x25c(%rbp)
je     12e6 <check_backup_name+0x166>
cmpl   $0x2e,-0x25c(%rbp)
jne    12eb <check_backup_name+0x16b>
jmp    131c <check_backup_name+0x19c>
cmpl   $0x0,-0x8(%rbp)
je     1310 <check_backup_name+0x190>
lea    -0x50(%rbp),%rsi
mov    -0x25c(%rbp),%eax
movsbl %al,%edx
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1060 <ui_print@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    13c3 <check_backup_name+0x243>
jmp    1321 <check_backup_name+0x1a1>
mov    -0x258(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x258(%rbp)
jmp    1233 <check_backup_name+0xb3>
lea    -0x150(%rbp),%rax
mov    %rax,-0x270(%rbp)
lea    0xd18(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
mov    -0x270(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
lea    -0x250(%rbp),%rdi
lea    -0x150(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    0xcfe(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x250(%rbp),%rdi
lea    -0x260(%rbp),%rsi
call   1090 <statfs@plt>
cmp    $0x0,%rax
jne    13bc <check_backup_name+0x23c>
cmpl   $0x0,-0x8(%rbp)
je     13b0 <check_backup_name+0x230>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1060 <ui_print@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    13c3 <check_backup_name+0x243>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_backup_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x258,%rsp
mov    %edi,%r14d
lea    0xe69(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
mov    %eax,%edi
call   1050 <strlen@plt>
cmp    $0x41,%eax
jl     11ca <check_backup_name+0x4a>
mov    $0xfffffffe,%r15d
test   %r14d,%r14d
je     12c0 <check_backup_name+0x140>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1060 <ui_print@plt>
jmp    12c0 <check_backup_name+0x140>
mov    %eax,%ebp
lea    0xe2d(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1030 <strncpy@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     12c0 <check_backup_name+0x140>
test   %ebp,%ebp
jle    1274 <check_backup_name+0xf4>
mov    %ebp,%eax
xor    %ecx,%ecx
jmp    1219 <check_backup_name+0x99>
xchg   %ax,%ax
add    $0x1,%rcx
cmp    %rcx,%rax
je     1274 <check_backup_name+0xf4>
movzbl 0x10(%rsp,%rcx,1),%edx
lea    -0x30(%rdx),%esi
cmp    $0xa,%sil
jb     1210 <check_backup_name+0x90>
mov    %edx,%ebx
and    $0xfd,%bl
cmp    $0x5d,%bl
je     1210 <check_backup_name+0x90>
lea    -0x41(%rdx),%esi
cmp    $0x1b,%sil
jb     1210 <check_backup_name+0x90>
lea    -0x61(%rdx),%esi
cmp    $0x1b,%sil
jb     1210 <check_backup_name+0x90>
lea    -0x2d(%rdx),%esi
cmp    $0x2,%sil
jb     1210 <check_backup_name+0x90>
cmp    $0x7d,%dl
je     1210 <check_backup_name+0x90>
mov    $0xfffffffd,%r15d
test   %r14d,%r14d
je     12c0 <check_backup_name+0x140>
movsbl %dl,%edx
lea    0xdc7(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <ui_print@plt>
jmp    12c0 <check_backup_name+0x140>
lea    0xde7(%rip),%rdi
call   1070 <DataManager_GetStrValue@plt>
lea    0x150(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
lea    0xddb(%rip),%rsi
lea    0x50(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   10a0 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <statfs@plt>
test   %rax,%rax
je     12d1 <check_backup_name+0x151>
mov    %r15d,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfffffffc,%r15d
test   %r14d,%r14d
je     12c0 <check_backup_name+0x140>
lea    0xd99(%rip),%rdi
jmp    11be <check_backup_name+0x3e>

LLVM IR (-O0):
%struct.statfs = type { i32 }
@.str = [15 x i8] c"tw_backup_name\00"
@.str.1 = [28 x i8] c"E:Backup name is too long.\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [53 x i8] c"E:Backup name '%s' contains invalid character: '%c'\0A\00"
@.str.4 = [18 x i8] c"tw_backups_folder\00"
@.str.5 = [8 x i8] c"%s/%s/.\00"
@.str.6 = [43 x i8] c"E:A backup with this name already exists.\0A\00"
define i32 @check_backup_name(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [255 x i8]
%6 = alloca [255 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.statfs
store i32 %0, i32* %3
%11 = call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strlen(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 64
br i1 %14, label %15, label %21
15: ; preds = %1
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
store i32 -2, i32* %2
br label %106
21: ; preds = %1
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%23 = call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %7
%25 = call i32 @strncpy(i8* %22, i32 %23, i32 %24)
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 0, i32* %2
br label %106
30: ; preds = %21
store i32 0, i32* %8
br label %31
31: ; preds = %85, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %88
35: ; preds = %31
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp sge i32 %41, 48
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %9
%45 = icmp sle i32 %44, 57
br i1 %45, label %73, label %46
46: ; preds = %43, %35
%47 = load i32, i32* %9
%48 = icmp sge i32 %47, 65
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %9
%51 = icmp sle i32 %50, 91
br i1 %51, label %73, label %52
52: ; preds = %49, %46
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 93
br i1 %54, label %73, label %55
55: ; preds = %52
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 95
br i1 %57, label %73, label %58
58: ; preds = %55
%59 = load i32, i32* %9
%60 = icmp sge i32 %59, 97
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %9
%63 = icmp sle i32 %62, 123
br i1 %63, label %73, label %64
64: ; preds = %61, %58
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, 125
br i1 %66, label %73, label %67
67: ; preds = %64
%68 = load i32, i32* %9
%69 = icmp eq i32 %68, 45
br i1 %69, label %73, label %70
70: ; preds = %67
%71 = load i32, i32* %9
%72 = icmp eq i32 %71, 46
br i1 %72, label %73, label %74
73: ; preds = %70, %67, %64, %61, %55, %52, %49, %43
br label %84
74: ; preds = %70
%75 = load i32, i32* %3
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %83
77: ; preds = %74
%78 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%79 = load i32, i32* %9
%80 = trunc i32 %79 to i8
%81 = sext i8 %80 to i32
%82 = call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %78, i32 %81)
br label %83
83: ; preds = %77, %74
store i32 -3, i32* %2
br label %106
84: ; preds = %73
br label %85
85: ; preds = %84
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 1
store i32 %87, i32* %8
br label %31
88: ; preds = %31
%89 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%90 = call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%91 = call i32 @strcpy(i8* %89, i32 %90)
%92 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%93 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%94 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%95 = call i32 @sprintf(i8* %92, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %93, i8* %94)
%96 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%97 = call i64 @statfs(i8* %96, %struct.statfs* %10)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %105
99: ; preds = %88
%100 = load i32, i32* %3
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %104
104: ; preds = %102, %99
store i32 -4, i32* %2
br label %106
105: ; preds = %88
store i32 0, i32* %2
br label %106
106: ; preds = %105, %104, %83, %29, %20
%107 = load i32, i32* %2
ret i32 %107
}

LLVM IR (-O2):
%struct.statfs = type { i32 }
@.str = [15 x i8] c"tw_backup_name\00"
@.str.1 = [28 x i8] c"E:Backup name is too long.\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [53 x i8] c"E:Backup name '%s' contains invalid character: '%c'\0A\00"
@.str.4 = [18 x i8] c"tw_backups_folder\00"
@.str.5 = [8 x i8] c"%s/%s/.\00"
@.str.6 = [43 x i8] c"E:A backup with this name already exists.\0A\00"
define i32 @check_backup_name(i32 %0) {
%2 = alloca [64 x i8]
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca %struct.statfs
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @strlen(i32 %9)
%11 = bitcast %struct.statfs* %5 to i8*
%12 = icmp sgt i32 %10, 64
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = icmp eq i32 %0, 0
br i1 %14, label %62, label %15
15: ; preds = %13
%16 = tail call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %62
17: ; preds = %1
%18 = tail call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @strncpy(i8* %6, i32 %18, i32 %10)
%20 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %62, label %22
22: ; preds = %17
%23 = icmp sgt i32 %10, 0
br i1 %23, label %24, label %52
24: ; preds = %22
%25 = zext i32 %10 to i64
br label %26
26: ; preds = %24, %49
%27 = phi i64 [ 0, %24 ], [ %50, %49 ]
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = add i8 %29, -48
%31 = icmp ult i8 %30, 10
br i1 %31, label %49, label %32
32: ; preds = %26
%33 = add i8 %29, -65
%34 = icmp ult i8 %33, 27
%35 = and i8 %29, -3
%36 = icmp eq i8 %35, 93
%37 = or i1 %36, %34
br i1 %37, label %49, label %38
38: ; preds = %32
%39 = freeze i8 %29
%40 = add i8 %39, -97
%41 = icmp ult i8 %40, 27
br i1 %41, label %49, label %42
42: ; preds = %38
switch i8 %39, label %43 [
i8 125, label %49
i8 46, label %49
i8 45, label %49
]
43: ; preds = %42
%44 = freeze i8 %29
%45 = icmp eq i32 %0, 0
br i1 %45, label %62, label %46
46: ; preds = %43
%47 = sext i8 %44 to i32
%48 = call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %47)
br label %62
49: ; preds = %42, %42, %42, %38, %32, %26
%50 = add nuw nsw i64 %27, 1
%51 = icmp eq i64 %50, %25
br i1 %51, label %52, label %26
52: ; preds = %49, %22
%53 = call i32 @DataManager_GetStrValue(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @strcpy(i8* %7, i32 %53)
%55 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %7, i8* %6)
%56 = call i64 @statfs(i8* %8, %struct.statfs* %5)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %52
%59 = icmp eq i32 %0, 0
br i1 %59, label %62, label %60
60: ; preds = %58
%61 = call i32 (i8*, ...) @ui_print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %52, %58, %60, %43, %46, %17, %13, %15
%63 = phi i32 [ -2, %15 ], [ -2, %13 ], [ 0, %17 ], [ -3, %46 ], [ -3, %43 ], [ -4, %60 ], [ -4, %58 ], [ 0, %52 ]
ret i32 %63
}