#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 *dirname(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
int path_is_in_dir(const char *parent, const char *path) {
  char *tmp = strdup(path);
  char *curr_dir = tmp;
  int ret;
  while (strcmp(parent, curr_dir) != 0) {
    if (strcmp(curr_dir, "/") == 0) {
      ret = 0;
      goto out;
    }
    curr_dir = dirname(curr_dir);
  }
  ret = 1;
out:
  free(tmp);
  return ret;
}


x86 assembly (clang, -O0):
<path_is_in_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b4 <path_is_in_dir+0x74>
mov    -0x20(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a2 <path_is_in_dir+0x62>
movl   $0x0,-0x24(%rbp)
jmp    11bb <path_is_in_dir+0x7b>
mov    -0x20(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x20(%rbp)
jmp    1165 <path_is_in_dir+0x25>
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_in_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1060 <strdup@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11b0 <path_is_in_dir+0x70>
lea    0xe8d(%rip),%r12
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ad <path_is_in_dir+0x6d>
mov    %rbx,%rdi
call   1040 <dirname@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1180 <path_is_in_dir+0x40>
jmp    11b0 <path_is_in_dir+0x70>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @path_is_in_dir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
store i8* %10, i8** %6
br label %11
11: ; preds = %21, %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %6
%14 = call i64 @strcmp(i8* %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %7
br label %25
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = call i8* @dirname(i8* %22)
store i8* %23, i8** %6
br label %11
24: ; preds = %11
store i32 1, i32* %7
br label %25
25: ; preds = %24, %20
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @path_is_in_dir(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strdup(i8* %1)
%4 = tail call i64 @strcmp(i8* %0, i8* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2, %10
%7 = phi i8* [ %11, %10 ], [ %3, %2 ]
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i8* @dirname(i8* %7)
%12 = tail call i64 @strcmp(i8* %0, i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %10, %2
%15 = phi i32 [ 1, %2 ], [ 1, %10 ], [ 0, %6 ]
%16 = tail call i32 @free(i8* %3)
ret i32 %15
}