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

/* Variables and functions */
int /*<<< orphan*/ catdoc_main(int, char **);
int /*<<< orphan*/ docx_to_text(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getext_(char *);
int /*<<< orphan*/ pdf_to_text(char *, char *);
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
int do_extract_text(char *input_file, char *output_file) {
  char *ext = NULL;
  ext = (char *)getext_(input_file);
  if (ext == NULL)
    return 1;
  if ((strcasecmp(ext, "doc") == 0) || (strcasecmp(ext, "rtf") == 0)) {
    char *argv_catdoc[] = {"catdoc", input_file};
    int argc_catdoc = sizeof(argv_catdoc) / sizeof(char *);
    catdoc_main((int)argc_catdoc, argv_catdoc);
  } else if ((strcasecmp(ext, "txt") == 0) || (strcasecmp(ext, "sh") == 0) ||
             (strcasecmp(ext, "html") == 0) || (strcasecmp(ext, "c") == 0)) {
    output_file[strlen(output_file) - 4] = '\0';
  } else if (strcasecmp(ext, "docx") == 0) {
    docx_to_text(input_file, output_file);
  } else if (strcasecmp(ext, "odt") == 0) {
    docx_to_text(input_file, output_file);
  } else if (strcasecmp(ext, "pdf") == 0) {
    pdf_to_text(input_file, output_file);
  } else {
    free(ext);
    return 1;
  }
  free(ext);
  return 0;
}


x86 assembly (clang, -O0):
<do_extract_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <getext_@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ac <do_extract_text+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1356 <do_extract_text+0x1e6>
mov    -0x20(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     11e0 <do_extract_text+0x70>
mov    -0x20(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    120b <do_extract_text+0x9b>
lea    0xe1d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x34(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1090 <catdoc_main@plt>
jmp    1346 <do_extract_text+0x1d6>
mov    -0x20(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1273 <do_extract_text+0x103>
mov    -0x20(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1273 <do_extract_text+0x103>
mov    -0x20(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1273 <do_extract_text+0x103>
mov    -0x20(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1299 <do_extract_text+0x129>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1341 <do_extract_text+0x1d1>
mov    -0x20(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12c5 <do_extract_text+0x155>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <docx_to_text@plt>
jmp    133c <do_extract_text+0x1cc>
mov    -0x20(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12f1 <do_extract_text+0x181>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <docx_to_text@plt>
jmp    1337 <do_extract_text+0x1c7>
mov    -0x20(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    131d <do_extract_text+0x1ad>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <pdf_to_text@plt>
jmp    1332 <do_extract_text+0x1c2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1356 <do_extract_text+0x1e6>
jmp    1337 <do_extract_text+0x1c7>
jmp    133c <do_extract_text+0x1cc>
jmp    1341 <do_extract_text+0x1d1>
jmp    1346 <do_extract_text+0x1d6>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_extract_text>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1080 <getext_@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     129d <do_extract_text+0x12d>
mov    %rax,%rbx
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1264 <do_extract_text+0xf4>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1264 <do_extract_text+0xf4>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1283 <do_extract_text+0x113>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1283 <do_extract_text+0x113>
lea    0xe15(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1283 <do_extract_text+0x113>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1283 <do_extract_text+0x113>
lea    0xdf2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12aa <do_extract_text+0x13a>
lea    0xde3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12aa <do_extract_text+0x13a>
lea    0xdd3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12b7 <do_extract_text+0x147>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    129d <do_extract_text+0x12d>
lea    0xd99(%rip),%rax
mov    %rax,(%rsp)
mov    %r15,0x8(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edi
call   1090 <catdoc_main@plt>
jmp    1293 <do_extract_text+0x123>
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x4(%rax,%r14,1)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <docx_to_text@plt>
jmp    1293 <do_extract_text+0x123>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <pdf_to_text@plt>
jmp    1293 <do_extract_text+0x123>

LLVM IR (-O0):
@.str = [4 x i8] c"doc\00"
@.str.1 = [4 x i8] c"rtf\00"
@.str.2 = [7 x i8] c"catdoc\00"
@.str.3 = [4 x i8] c"txt\00"
@.str.4 = [3 x i8] c"sh\00"
@.str.5 = [5 x i8] c"html\00"
@.str.6 = [2 x i8] c"c\00"
@.str.7 = [5 x i8] c"docx\00"
@.str.8 = [4 x i8] c"odt\00"
@.str.9 = [4 x i8] c"pdf\00"
define i32 @do_extract_text(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [2 x i8*]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%9 = load i8*, i8** %4
%10 = call i64 @getext_(i8* %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %87
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i64 @strcasecmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i64 @strcasecmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19, %15
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %4
store i8* %26, i8** %25
store i32 2, i32* %8
%27 = load i32, i32* %8
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%29 = call i32 @catdoc_main(i32 %27, i8** %28)
br label %84
30: ; preds = %19
%31 = load i8*, i8** %6
%32 = call i64 @strcasecmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %46, label %34
34: ; preds = %30
%35 = load i8*, i8** %6
%36 = call i64 @strcasecmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = call i64 @strcasecmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i8*, i8** %6
%44 = call i64 @strcasecmp(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42, %38, %34, %30
%47 = load i8*, i8** %5
%48 = load i8*, i8** %5
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 %49, 4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
store i8 0, i8* %52
br label %83
53: ; preds = %42
%54 = load i8*, i8** %6
%55 = call i64 @strcasecmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = load i8*, i8** %5
%60 = call i32 @docx_to_text(i8* %58, i8* %59)
br label %82
61: ; preds = %53
%62 = load i8*, i8** %6
%63 = call i64 @strcasecmp(i8* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i8*, i8** %4
%67 = load i8*, i8** %5
%68 = call i32 @docx_to_text(i8* %66, i8* %67)
br label %81
69: ; preds = %61
%70 = load i8*, i8** %6
%71 = call i64 @strcasecmp(i8* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %69
%74 = load i8*, i8** %4
%75 = load i8*, i8** %5
%76 = call i32 @pdf_to_text(i8* %74, i8* %75)
br label %80
77: ; preds = %69
%78 = load i8*, i8** %6
%79 = call i32 @free(i8* %78)
store i32 1, i32* %3
br label %87
80: ; preds = %73
br label %81
81: ; preds = %80, %65
br label %82
82: ; preds = %81, %57
br label %83
83: ; preds = %82, %46
br label %84
84: ; preds = %83, %23
%85 = load i8*, i8** %6
%86 = call i32 @free(i8* %85)
store i32 0, i32* %3
br label %87
87: ; preds = %84, %77, %14
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [4 x i8] c"doc\00"
@.str.1 = [4 x i8] c"rtf\00"
@.str.2 = [7 x i8] c"catdoc\00"
@.str.3 = [4 x i8] c"txt\00"
@.str.4 = [3 x i8] c"sh\00"
@.str.5 = [5 x i8] c"html\00"
@.str.6 = [2 x i8] c"c\00"
@.str.7 = [5 x i8] c"docx\00"
@.str.8 = [4 x i8] c"odt\00"
@.str.9 = [4 x i8] c"pdf\00"
define i32 @do_extract_text(i8* %0, i8* %1) {
%3 = alloca [2 x i8*]
%4 = tail call i64 @getext_(i8* %0)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %54, label %7
7: ; preds = %2
%8 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10, %7
%14 = bitcast [2 x i8*]* %3 to i8*
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* %0, i8** %16
%17 = call i32 @catdoc_main(i32 2, i8** %15)
br label %52
18: ; preds = %10
%19 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27, %24, %21, %18
%31 = tail call i32 @strlen(i8* %1)
%32 = add nsw i32 %31, -4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
store i8 0, i8* %34
br label %52
35: ; preds = %27
%36 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @docx_to_text(i8* %0, i8* %1)
br label %52
40: ; preds = %35
%41 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i32 @docx_to_text(i8* %0, i8* %1)
br label %52
45: ; preds = %40
%46 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 @pdf_to_text(i8* %0, i8* %1)
br label %52
50: ; preds = %45
%51 = tail call i32 @free(i8* %5)
br label %54
52: ; preds = %30, %43, %48, %38, %13
%53 = call i32 @free(i8* %5)
br label %54
54: ; preds = %2, %52, %50
%55 = phi i32 [ 0, %52 ], [ 1, %50 ], [ 1, %2 ]
ret i32 %55
}