#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 */
scalar_t__ exist_file(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
char *strrchr(char *, char);
int test_file(const char *local) {
  char buff[1024], *p;
  int comp = 0;
  strcpy(buff, local);
  if ((p = strrchr(buff, '.')) &&
      (!strcmp(p, ".z") || !strcmp(p, ".gz") || !strcmp(p, ".zip") ||
       !strcmp(p, ".Z") || !strcmp(p, ".GZ") || !strcmp(p, ".ZIP"))) {
    *p = '\0';
    if (exist_file(buff))
      return 1;
    comp = 1;
  }
  if ((p = strrchr(buff, '.')) && strlen(p) == 4 &&
      (*(p + 3) == 'd' || *(p + 3) == 'D')) {
    *(p + 3) = *(p + 3) == 'd' ? 'o' : 'O';
    if (exist_file(buff))
      return 1;
    comp = 1;
  }
  if (!exist_file(buff))
    return 0;
  return comp ? 2 : 1;
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     1279 <test_file+0x129>
mov    -0x418(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1243 <test_file+0xf3>
mov    -0x418(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1243 <test_file+0xf3>
mov    -0x418(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1243 <test_file+0xf3>
mov    -0x418(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1243 <test_file+0xf3>
mov    -0x418(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1243 <test_file+0xf3>
mov    -0x418(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1279 <test_file+0x129>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
call   1070 <exist_file@plt>
cmp    $0x0,%rax
je     126f <test_file+0x11f>
movl   $0x1,-0x4(%rbp)
jmp    1366 <test_file+0x216>
movl   $0x1,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     132b <test_file+0x1db>
mov    -0x418(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jne    132b <test_file+0x1db>
mov    -0x418(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x64,%eax
je     12d8 <test_file+0x188>
mov    -0x418(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x44,%eax
jne    132b <test_file+0x1db>
mov    -0x418(%rbp),%rax
movsbl 0x3(%rax),%edx
mov    $0x4f,%eax
mov    $0x6f,%ecx
cmp    $0x64,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x418(%rbp),%rax
mov    %cl,0x3(%rax)
lea    -0x410(%rbp),%rdi
call   1070 <exist_file@plt>
cmp    $0x0,%rax
je     1321 <test_file+0x1d1>
movl   $0x1,-0x4(%rbp)
jmp    1366 <test_file+0x216>
movl   $0x1,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
call   1070 <exist_file@plt>
cmp    $0x0,%rax
jne    134d <test_file+0x1fd>
movl   $0x0,-0x4(%rbp)
jmp    1366 <test_file+0x216>
mov    -0x41c(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1209 <test_file+0xb9>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f4 <test_file+0xa4>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f4 <test_file+0xa4>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f4 <test_file+0xa4>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f4 <test_file+0xa4>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f4 <test_file+0xa4>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1209 <test_file+0xb9>
movb   $0x0,(%rbx)
mov    %rsp,%rdi
call   1070 <exist_file@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1273 <test_file+0x123>
mov    %rsp,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1257 <test_file+0x107>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jne    1257 <test_file+0x107>
mov    0x3(%rbx),%al
mov    %eax,%ecx
or     $0x20,%cl
cmp    $0x64,%cl
jne    1257 <test_file+0x107>
cmp    $0x64,%al
sete   %al
shl    $0x5,%al
or     $0x4f,%al
mov    %al,0x3(%rbx)
mov    %rsp,%rdi
call   1070 <exist_file@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1273 <test_file+0x123>
mov    %rsp,%rdi
call   1070 <exist_file@plt>
test   %rax,%rax
je     1271 <test_file+0x121>
cmp    $0x1,%ebp
mov    $0x2,%ebp
sbb    $0x0,%ebp
jmp    1273 <test_file+0x123>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c".z\00"
@.str.1 = [4 x i8] c".gz\00"
@.str.2 = [5 x i8] c".zip\00"
@.str.3 = [3 x i8] c".Z\00"
@.str.4 = [4 x i8] c".GZ\00"
@.str.5 = [5 x i8] c".ZIP\00"
define i32 @test_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %44
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %44, label %37
37: ; preds = %33, %29, %25, %21, %17, %13
%38 = load i8*, i8** %5
store i8 0, i8* %38
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = call i64 @exist_file(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 1, i32* %2
br label %90
43: ; preds = %37
store i32 1, i32* %6
br label %44
44: ; preds = %43, %33, %1
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%46 = call i8* @strrchr(i8* %45, i8 signext 46)
store i8* %46, i8** %5
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %80
48: ; preds = %44
%49 = load i8*, i8** %5
%50 = call i32 @strlen(i8* %49)
%51 = icmp eq i32 %50, 4
br i1 %51, label %52, label %80
52: ; preds = %48
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 3
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 100
br i1 %57, label %64, label %58
58: ; preds = %52
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 68
br i1 %63, label %64, label %80
64: ; preds = %58, %52
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i64 3
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 100
%70 = zext i1 %69 to i64
%71 = select i1 %69, i32 111, i32 79
%72 = trunc i32 %71 to i8
%73 = load i8*, i8** %5
%74 = getelementptr inbounds i8, i8* %73, i64 3
store i8 %72, i8* %74
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%76 = call i64 @exist_file(i8* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %64
store i32 1, i32* %2
br label %90
79: ; preds = %64
store i32 1, i32* %6
br label %80
80: ; preds = %79, %58, %48, %44
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%82 = call i64 @exist_file(i8* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %85, label %84
84: ; preds = %80
store i32 0, i32* %2
br label %90
85: ; preds = %80
%86 = load i32, i32* %6
%87 = icmp ne i32 %86, 0
%88 = zext i1 %87 to i64
%89 = select i1 %87, i32 2, i32 1
store i32 %89, i32* %2
br label %90
90: ; preds = %85, %84, %78, %42
%91 = load i32, i32* %2
ret i32 %91
}

LLVM IR (-O2):
@.str = [3 x i8] c".z\00"
@.str.1 = [4 x i8] c".gz\00"
@.str.2 = [5 x i8] c".zip\00"
@.str.3 = [3 x i8] c".Z\00"
@.str.4 = [4 x i8] c".GZ\00"
@.str.5 = [5 x i8] c".ZIP\00"
define i32 @test_file(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i8* @strrchr(i8* %3, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %28, label %7
7: ; preds = %1
%8 = call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = call i32 @strcmp(i8* %5, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = call i32 @strcmp(i8* %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = call i32 @strcmp(i8* %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @strcmp(i8* %5, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i32 @strcmp(i8* %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %19, %16, %13, %10, %7
store i8 0, i8* %5
%26 = call i64 @exist_file(i8* %3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %50
28: ; preds = %25, %22, %1
%29 = phi i32 [ 0, %22 ], [ 0, %1 ], [ 1, %25 ]
%30 = call i8* @strrchr(i8* %3, i8 signext 46)
%31 = icmp eq i8* %30, null
br i1 %31, label %43, label %32
32: ; preds = %28
%33 = call i32 @strlen(i8* %30)
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = getelementptr inbounds i8, i8* %30, i64 3
%37 = load i8, i8* %36
switch i8 %37, label %43 [
i8 100, label %38
i8 68, label %38
]
38: ; preds = %35, %35
%39 = icmp eq i8 %37, 100
%40 = select i1 %39, i8 111, i8 79
store i8 %40, i8* %36
%41 = call i64 @exist_file(i8* %3)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %38, %35, %32, %28
%44 = phi i32 [ %29, %32 ], [ %29, %28 ], [ %29, %35 ], [ 1, %38 ]
%45 = call i64 @exist_file(i8* %3)
%46 = icmp eq i64 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %43
%48 = icmp eq i32 %44, 0
%49 = select i1 %48, i32 1, i32 2
br label %50
50: ; preds = %43, %38, %25, %47
%51 = phi i32 [ %49, %47 ], [ 1, %25 ], [ 1, %38 ], [ 0, %43 ]
ret i32 %51
}