#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
char *_DtQualifyWithFirst(char *filename, char *searchPath) {
  char *paths = searchPath;
  char *path;
  char *chance;
  FILE *f;
  if (filename == NULL || searchPath == NULL || filename[0] == 0 ||
      searchPath[0] == 0)
    return NULL;
  while (1) {
    if ((path = strchr(paths, ':')) != NULL)
      *path = 0;
    chance = (char *)malloc(strlen(paths) + strlen(filename) + 2);
    if (filename[0] == '/')
      sprintf(chance, "%s%s", paths, filename);
    else
      sprintf(chance, "%s/%s", paths, filename);
    if (f = fopen(chance, "r")) {
      fclose(f);
      if (path)
        *path = ':';
      return chance;
    }
    free(chance);
    if (path == NULL)
      break;
    *path = ':';
    paths = path + 1;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<_DtQualifyWithFirst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11be <_DtQualifyWithFirst+0x4e>
cmpq   $0x0,-0x18(%rbp)
je     11be <_DtQualifyWithFirst+0x4e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11be <_DtQualifyWithFirst+0x4e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11cb <_DtQualifyWithFirst+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    12e1 <_DtQualifyWithFirst+0x171>
jmp    11d0 <_DtQualifyWithFirst+0x60>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f3 <_DtQualifyWithFirst+0x83>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    124a <_DtQualifyWithFirst+0xda>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdc0(%rip),%rsi
call   1090 <sprintf@plt>
jmp    1262 <_DtQualifyWithFirst+0xf2>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xda8(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12a8 <_DtQualifyWithFirst+0x138>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     129b <_DtQualifyWithFirst+0x12b>
mov    -0x28(%rbp),%rax
movb   $0x3a,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e1 <_DtQualifyWithFirst+0x171>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    12c1 <_DtQualifyWithFirst+0x151>
jmp    12d9 <_DtQualifyWithFirst+0x169>
mov    -0x28(%rbp),%rax
movb   $0x3a,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <_DtQualifyWithFirst+0x60>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DtQualifyWithFirst>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
test   %rdi,%rdi
je     124a <_DtQualifyWithFirst+0xda>
mov    %rsi,%r12
test   %rsi,%rsi
je     124a <_DtQualifyWithFirst+0xda>
mov    %rdi,%r15
cmpb   $0x0,(%rdi)
je     1247 <_DtQualifyWithFirst+0xd7>
cmpb   $0x0,(%r12)
je     1247 <_DtQualifyWithFirst+0xd7>
lea    0xe54(%rip),%rbp
lea    0xe53(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d8 <_DtQualifyWithFirst+0x68>
movb   $0x0,(%rbx)
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r13,1),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
cmpb   $0x2f,(%r15)
mov    %rbp,%rsi
lea    0xdf7(%rip),%rax
cmove  %rax,%rsi
mov    %r13,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1090 <sprintf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    125c <_DtQualifyWithFirst+0xec>
mov    %r13,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1247 <_DtQualifyWithFirst+0xd7>
movb   $0x3a,(%rbx)
add    $0x1,%rbx
mov    %rbx,%r12
jmp    11c0 <_DtQualifyWithFirst+0x50>
xor    %r13d,%r13d
mov    %r13,%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   %rbx,%rbx
je     124a <_DtQualifyWithFirst+0xda>
movb   $0x3a,(%rbx)
jmp    124a <_DtQualifyWithFirst+0xda>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @_DtQualifyWithFirst(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %38, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %38, label %9
9: ; preds = %6
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %38, label %12
12: ; preds = %9, %36
%13 = phi i8* [ %37, %36 ], [ %1, %9 ]
%14 = tail call i8* @strchr(i8* %13, i8 signext 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %12
store i8 0, i8* %14
br label %17
17: ; preds = %16, %12
%18 = tail call i64 @strlen(i8* %13)
%19 = tail call i64 @strlen(i8* %0)
%20 = add i64 %18, 2
%21 = add i64 %20, %19
%22 = tail call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i8, i8* %0
%25 = icmp eq i8 %24, 47
%26 = select i1 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%27 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) %26, i8* %13, i8* %0)
%28 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %34, label %30
30: ; preds = %17
%31 = inttoptr i64 %22 to i8*
%32 = tail call i32 @fclose(i32* %28)
br i1 %15, label %38, label %33
33: ; preds = %30
store i8 58, i8* %14
br label %38
34: ; preds = %17
%35 = tail call i32 @free(i8* %23)
br i1 %15, label %38, label %36
36: ; preds = %34
store i8 58, i8* %14
%37 = getelementptr inbounds i8, i8* %14, i64 1
br label %12
38: ; preds = %34, %30, %33, %2, %6, %9
%39 = phi i8* [ null, %9 ], [ null, %6 ], [ null, %2 ], [ %31, %33 ], [ %31, %30 ], [ null, %34 ]
ret i8* %39
}