#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 */
char *get_fileext(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
void unpack(int argc, char **argv) {
  int i;
  for (i = 2; i < argc; ++i) {
    char *filext;
    char buffer[512];
    memset(buffer, 0, 512);
    filext = get_fileext(argv[i]);
    printf("Fext: %s\n", filext);
    strcpy(buffer, "tar");
    if (strcmp(filext, "gz") == 0)
      strcat(buffer, " xfvz ");
    else if (strcmp(filext, "bz2") == 0)
      strcat(buffer, " xfvj ");
    else if (strcmp(filext, "xz") == 0)
      strcat(buffer, " xfvJ ");
    else
      return;
    strcat(buffer, argv[i]);
    system(buffer);
  }
}


x86 assembly (clang, -O0):
<unpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b7 <unpack+0x147>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <get_fileext@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
lea    -0x220(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1212 <unpack+0xa2>
lea    -0x220(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1090 <strcat@plt>
jmp    1285 <unpack+0x115>
mov    -0x20(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1244 <unpack+0xd4>
lea    -0x220(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1090 <strcat@plt>
jmp    1280 <unpack+0x110>
mov    -0x20(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <unpack+0x106>
lea    -0x220(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1090 <strcat@plt>
jmp    127b <unpack+0x10b>
jmp    12b7 <unpack+0x147>
jmp    1280 <unpack+0x110>
jmp    1285 <unpack+0x115>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <strcat@plt>
lea    -0x220(%rbp),%rdi
call   1040 <system@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <unpack+0x19>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x3,%edi
jl     1267 <unpack+0xf7>
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x2,%r12d
mov    %rsp,%rbx
lea    0xe71(%rip),%r13
jmp    11d9 <unpack+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    (%r14,%r12,8),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     1267 <unpack+0xf7>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    (%r14,%r12,8),%rdi
call   1080 <get_fileext@plt>
mov    %rax,%rbp
lea    0xe05(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0xdfd(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
lea    0xdf2(%rip),%rsi
call   1070 <strcmp@plt>
mov    %r13,%rsi
test   %rax,%rax
je     11b0 <unpack+0x40>
mov    %rbp,%rdi
lea    0xde5(%rip),%rsi
call   1070 <strcmp@plt>
lea    0xddd(%rip),%rsi
test   %rax,%rax
je     11b0 <unpack+0x40>
mov    %rbp,%rdi
lea    0xdd1(%rip),%rsi
call   1070 <strcmp@plt>
lea    0xdc8(%rip),%rsi
test   %rax,%rax
je     11b0 <unpack+0x40>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Fext: %s\0A\00"
@.str.1 = [4 x i8] c"tar\00"
@.str.2 = [3 x i8] c"gz\00"
@.str.3 = [7 x i8] c" xfvz \00"
@.str.4 = [4 x i8] c"bz2\00"
@.str.5 = [7 x i8] c" xfvj \00"
@.str.6 = [3 x i8] c"xz\00"
@.str.7 = [7 x i8] c" xfvJ \00"
define void @unpack(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [512 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 2, i32* %5
br label %8
8: ; preds = %58, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %61
12: ; preds = %8
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 512)
%15 = load i8**, i8*** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i8* @get_fileext(i8* %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %6
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %12
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %48
31: ; preds = %12
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %47
38: ; preds = %31
%39 = load i8*, i8** %6
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %46
45: ; preds = %38
br label %61
46: ; preds = %42
br label %47
47: ; preds = %46, %35
br label %48
48: ; preds = %47, %28
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%50 = load i8**, i8*** %4
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @strcat(i8* %49, i8* %54)
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%57 = call i32 @system(i8* %56)
br label %58
58: ; preds = %48
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %8
61: ; preds = %45, %8
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Fext: %s\0A\00"
@.str.1 = [4 x i8] c"tar\00"
@.str.2 = [3 x i8] c"gz\00"
@.str.3 = [7 x i8] c" xfvz \00"
@.str.4 = [4 x i8] c"bz2\00"
@.str.5 = [7 x i8] c" xfvj \00"
@.str.6 = [3 x i8] c"xz\00"
@.str.7 = [7 x i8] c" xfvJ \00"
define void @unpack(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = icmp sgt i32 %0, 2
br i1 %4, label %5, label %33
5: ; preds = %2
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %24
%9 = phi i64 [ 2, %5 ], [ %30, %24 ]
%10 = call i32 @memset(i8* %6, i32 0, i32 512)
%11 = getelementptr inbounds i8*, i8** %1, i64 %9
%12 = load i8*, i8** %11
%13 = call i8* @get_fileext(i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %8
%19 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21, %18, %8
%25 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), %21 ]
%26 = call i32 @strcat(i8* %6, i8* %25)
%27 = load i8*, i8** %11
%28 = call i32 @strcat(i8* %6, i8* %27)
%29 = call i32 @system(i8* %6)
%30 = add nuw nsw i64 %9, 1
%31 = icmp eq i64 %30, %7
br i1 %31, label %33, label %8
32: ; preds = %21
br label %33
33: ; preds = %24, %2, %32
ret void
}