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

/* Variables and functions */
scalar_t__ calloc(scalar_t__, size_t);
int /*<<< orphan*/ check_alloc(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char look_for_column(char *, unsigned int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *search_datafile(int n, char **names, unsigned int *col,
                      unsigned int verbosity) {
  char valid = 0, validcol = 0;
  char *retname = NULL;
  int i;
  unsigned int hcol;
  FILE *test;
  for (i = n - 1; i > 0; i--) {
    if (names[i] != NULL) {
      valid = 0;
      if (strcmp(names[i], "-")) {
        if (col != 0)
          validcol = look_for_column(names[i], &hcol);
        test = fopen(names[i], "r");
        if (test == NULL) {
          fprintf(stderr, "File %s not found!\n", names[i]);
        } else {
          fclose(test);
          if ((col != 0) && (validcol == 1))
            *col = hcol;
          if (col != 0) {
            if (verbosity & 0x1)
              fprintf(stderr, "Using %s as datafile, reading column %u\n",
                      names[i], *col);
          } else {
            if (verbosity & 0x1)
              fprintf(stderr, "Using %s as datafile!\n", names[i]);
          }
          check_alloc(retname =
                          (char *)calloc(strlen(names[i]) + 1, (size_t)1));
          strcpy(retname, names[i]);
          names[i] = NULL;
          return retname;
        }
      } else {
        valid = 1;
        break;
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<search_datafile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
movb   $0x0,-0x26(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    13a3 <search_datafile+0x213>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1390 <search_datafile+0x200>
movb   $0x0,-0x25(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1382 <search_datafile+0x1f2>
cmpq   $0x0,-0x20(%rbp)
je     1225 <search_datafile+0x95>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <look_for_column@plt>
mov    %al,-0x26(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdca(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1274 <search_datafile+0xe4>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    137d <search_datafile+0x1ed>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     129e <search_datafile+0x10e>
movsbl -0x26(%rbp),%eax
cmp    $0x1,%eax
jne    129e <search_datafile+0x10e>
mov    -0x38(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     12e6 <search_datafile+0x156>
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12e1 <search_datafile+0x151>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    131d <search_datafile+0x18d>
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1318 <search_datafile+0x188>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    131d <search_datafile+0x18d>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   10b0 <check_alloc@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13ab <search_datafile+0x21b>
jmp    138b <search_datafile+0x1fb>
movb   $0x1,-0x25(%rbp)
jmp    13a3 <search_datafile+0x213>
jmp    1390 <search_datafile+0x200>
jmp    1395 <search_datafile+0x205>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11bf <search_datafile+0x2f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_datafile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     123d <search_datafile+0xad>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
mov    %ecx,(%rsp)
mov    %edi,%r12d
add    $0x1,%r12
add    $0xffffffff,%ebx
lea    0xe40(%rip),%rbp
xor    %r13d,%r13d
jmp    11dd <search_datafile+0x4d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%r12
add    $0xffffffff,%ebx
cmp    $0x2,%r12
jle    123d <search_datafile+0xad>
mov    %ebx,%ebx
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     11d0 <search_datafile+0x40>
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     123d <search_datafile+0xad>
test   %r15,%r15
je     120b <search_datafile+0x7b>
mov    (%r14,%rbx,8),%rdi
lea    0x4(%rsp),%rsi
call   10a0 <look_for_column@plt>
mov    %eax,%r13d
mov    (%r14,%rbx,8),%rdi
lea    0xdec(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1251 <search_datafile+0xc1>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    11d0 <search_datafile+0x40>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rdi
call   1040 <fclose@plt>
test   %r15,%r15
je     126b <search_datafile+0xdb>
cmp    $0x1,%r13b
jne    126b <search_datafile+0xdb>
mov    0x4(%rsp),%eax
mov    %eax,(%r15)
test   %r15,%r15
je     1296 <search_datafile+0x106>
testb  $0x1,(%rsp)
je     12b7 <search_datafile+0x127>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
mov    (%r15),%ecx
lea    0xd8b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12b7 <search_datafile+0x127>
testb  $0x1,(%rsp)
je     12b7 <search_datafile+0x127>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%rbx,8),%rdx
lea    0xd91(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r14,%rbx,8),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <check_alloc@plt>
mov    (%r14,%rbx,8),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
movq   $0x0,(%r14,%rbx,8)
jmp    123f <search_datafile+0xaf>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"File %s not found!\0A\00"
@.str.3 = [41 x i8] c"Using %s as datafile, reading column %u\0A\00"
@.str.4 = [23 x i8] c"Using %s as datafile!\0A\00"
define i8* @search_datafile(i32 %0, i8** %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i8 0, i8* %10
store i8 0, i8* %11
store i8* null, i8** %12
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %13
br label %18
18: ; preds = %133, %4
%19 = load i32, i32* %13
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %136
21: ; preds = %18
%22 = load i8**, i8*** %7
%23 = load i32, i32* %13
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %132
28: ; preds = %21
store i8 0, i8* %10
%29 = load i8**, i8*** %7
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %130
36: ; preds = %28
%37 = load i32*, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = load i8**, i8*** %7
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call signext i8 @look_for_column(i8* %44, i32* %14)
store i8 %45, i8* %11
br label %46
46: ; preds = %39, %36
%47 = load i8**, i8*** %7
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %52, i32** %15
%53 = load i32*, i32** %15
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %63
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %7
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %61)
br label %129
63: ; preds = %46
%64 = load i32*, i32** %15
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %8
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %75
68: ; preds = %63
%69 = load i8, i8* %11
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %75
72: ; preds = %68
%73 = load i32, i32* %14
%74 = load i32*, i32** %8
store i32 %73, i32* %74
br label %75
75: ; preds = %72, %68, %63
%76 = load i32*, i32** %8
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %93
78: ; preds = %75
%79 = load i32, i32* %9
%80 = and i32 %79, 1
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %92
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = load i8**, i8*** %7
%85 = load i32, i32* %13
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %84, i64 %86
%88 = load i8*, i8** %87
%89 = load i32*, i32** %8
%90 = load i32, i32* %89
%91 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %88, i32 %90)
br label %92
92: ; preds = %82, %78
br label %106
93: ; preds = %75
%94 = load i32, i32* %9
%95 = and i32 %94, 1
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %105
97: ; preds = %93
%98 = load i32, i32* @stderr
%99 = load i8**, i8*** %7
%100 = load i32, i32* %13
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %97, %93
br label %106
106: ; preds = %105, %92
%107 = load i8**, i8*** %7
%108 = load i32, i32* %13
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8*, i8** %107, i64 %109
%111 = load i8*, i8** %110
%112 = call i64 @strlen(i8* %111)
%113 = add nsw i64 %112, 1
%114 = call i64 @calloc(i64 %113, i64 1)
%115 = inttoptr i64 %114 to i8*
store i8* %115, i8** %12
%116 = call i32 @check_alloc(i8* %115)
%117 = load i8*, i8** %12
%118 = load i8**, i8*** %7
%119 = load i32, i32* %13
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8*, i8** %118, i64 %120
%122 = load i8*, i8** %121
%123 = call i32 @strcpy(i8* %117, i8* %122)
%124 = load i8**, i8*** %7
%125 = load i32, i32* %13
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i8*, i8** %124, i64 %126
store i8* null, i8** %127
%128 = load i8*, i8** %12
store i8* %128, i8** %5
br label %137
129: ; preds = %55
br label %131
130: ; preds = %28
store i8 1, i8* %10
br label %136
131: ; preds = %129
br label %132
132: ; preds = %131, %21
br label %133
133: ; preds = %132
%134 = load i32, i32* %13
%135 = add nsw i32 %134, -1
store i32 %135, i32* %13
br label %18
136: ; preds = %130, %18
store i8* null, i8** %5
br label %137
137: ; preds = %136, %106
%138 = load i8*, i8** %5
ret i8* %138
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"File %s not found!\0A\00"
@.str.3 = [41 x i8] c"Using %s as datafile, reading column %u\0A\00"
@.str.4 = [23 x i8] c"Using %s as datafile!\0A\00"
define i8* @search_datafile(i32 %0, i8** nocapture %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %69
8: ; preds = %4
%9 = icmp ne i32* %2, null
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %8, %65
%12 = phi i64 [ %10, %8 ], [ %68, %65 ]
%13 = phi i32 [ %0, %8 ], [ %15, %65 ]
%14 = phi i8 [ 0, %8 ], [ %66, %65 ]
%15 = add nsw i32 %13, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %65, label %20
20: ; preds = %11
%21 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %69, label %23
23: ; preds = %20
br i1 %9, label %24, label %27
24: ; preds = %23
%25 = load i8*, i8** %17
%26 = call signext i8 @look_for_column(i8* %25, i32* %5)
br label %27
27: ; preds = %24, %23
%28 = phi i8 [ %26, %24 ], [ %14, %23 ]
%29 = load i8*, i8** %17
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %17
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %65
36: ; preds = %27
%37 = call i32 @fclose(i32* %30)
%38 = icmp eq i8 %28, 1
%39 = select i1 %9, i1 %38, i1 false
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %5
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %36
%43 = and i32 %3, 1
%44 = icmp eq i32 %43, 0
br i1 %9, label %45, label %51
45: ; preds = %42
br i1 %44, label %56, label %46
46: ; preds = %45
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %17
%49 = load i32, i32* %2
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %48, i32 %49)
br label %56
51: ; preds = %42
br i1 %44, label %56, label %52
52: ; preds = %51
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %17
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %51, %52, %45, %46
%57 = load i8*, i8** %17
%58 = call i64 @strlen(i8* dereferenceable(1) %57)
%59 = add nsw i64 %58, 1
%60 = call i64 @calloc(i64 %59, i64 1)
%61 = inttoptr i64 %60 to i8*
%62 = call i32 @check_alloc(i8* %61)
%63 = load i8*, i8** %17
%64 = call i32 @strcpy(i8* %61, i8* %63)
store i8* null, i8** %17
br label %69
65: ; preds = %11, %32
%66 = phi i8 [ %28, %32 ], [ %14, %11 ]
%67 = icmp sgt i64 %12, 2
%68 = add nsw i64 %12, -1
br i1 %67, label %11, label %69
69: ; preds = %20, %65, %4, %56
%70 = phi i8* [ %61, %56 ], [ null, %4 ], [ null, %65 ], [ null, %20 ]
ret i8* %70
}