#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 */
int /*<<< orphan*/ debug(char *, char const *, char const *);
char *getenv(char const *);
int sscanf(char const *, char *, char *, int *);
int /*<<< orphan*/ strcmp(char *, char const *);
int fileinpath(const char *path, const char *envvar) {
  char *checkpath = getenv(envvar);
  const char *ptr = checkpath;
  char file[256];
  int n;
  if (checkpath == NULL) {
    return 1;
  }
  while (sscanf(ptr, "%255[^:]%n", file, &n) == 1) {
    if (!strcmp(file, path)) {
      return 1;
    }
    ptr += n;
    if (*ptr != ':')
      break;
    ++ptr;
  }
  debug("%s is not in %s.\n", path, envvar);
  return 0;
}


x86 assembly (clang, -O0):
<fileinpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <fileinpath+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    1225 <fileinpath+0xe5>
jmp    1184 <fileinpath+0x44>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    0xe6a(%rip),%rsi
lea    -0x134(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    120a <fileinpath+0xca>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d0 <fileinpath+0x90>
movl   $0x1,-0x4(%rbp)
jmp    1225 <fileinpath+0xe5>
mov    -0x134(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11f9 <fileinpath+0xb9>
jmp    120a <fileinpath+0xca>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1184 <fileinpath+0x44>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdf2(%rip),%rdi
call   1040 <debug@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileinpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <getenv@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     11ff <fileinpath+0xbf>
mov    %rax,%rbp
mov    %rbx,0x8(%rsp)
lea    0xe83(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11e8 <fileinpath+0xa8>
lea    0x10(%rsp),%rbx
lea    0xe60(%rip),%r13
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11ff <fileinpath+0xbf>
movslq 0x4(%rsp),%rax
cmpb   $0x3a,0x0(%rbp,%rax,1)
jne    11e8 <fileinpath+0xa8>
add    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11b0 <fileinpath+0x70>
lea    0xe1c(%rip),%rdi
mov    %r12,%rsi
mov    0x8(%rsp),%rdx
call   1040 <debug@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%255[^:]%n\00"
@.str.1 = [18 x i8] c"%s is not in %s.\0A\00"
define i32 @fileinpath(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @getenv(i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
store i8* %12, i8** %7
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %45
16: ; preds = %2
br label %17
17: ; preds = %38, %16
%18 = load i8*, i8** %7
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %19, i32* %9)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %41
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i32 @strcmp(i8* %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 1, i32* %3
br label %45
28: ; preds = %22
%29 = load i32, i32* %9
%30 = load i8*, i8** %7
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 58
br i1 %36, label %37, label %38
37: ; preds = %28
br label %41
38: ; preds = %28
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %7
br label %17
41: ; preds = %37, %17
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i32 @debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %41, %27, %15
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [11 x i8] c"%255[^:]%n\00"
@.str.1 = [18 x i8] c"%s is not in %s.\0A\00"
define i32 @fileinpath(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = tail call i8* @getenv(i8* %1)
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = icmp eq i8* %5, null
br i1 %8, label %28, label %9
9: ; preds = %2
%10 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %15, label %26
12: ; preds = %19
%13 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %4)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %26
15: ; preds = %9, %12
%16 = phi i8* [ %25, %12 ], [ %5, %9 ]
%17 = call i32 @strcmp(i8* %6, i8* dereferenceable(1) %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %15
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 58
%25 = getelementptr inbounds i8, i8* %22, i64 1
br i1 %24, label %12, label %26
26: ; preds = %12, %19, %9
%27 = call i32 @debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %28
28: ; preds = %15, %2, %26
%29 = phi i32 [ 0, %26 ], [ 1, %2 ], [ 1, %15 ]
ret i32 %29
}