#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 const *strchr(char const *, char);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
bool sametree(const char *s, const char *t) {
  int sn = strchr(s, '/') - s;
  int tn = strchr(t, '/') - t;
  return (sn == tn) && !strncmp(s, t, sn);
}


x86 assembly (clang, -O0):
<sametree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x19(%rbp)
jne    118c <sametree+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sametree>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
sub    %r15d,%ebx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
sub    %r14d,%ecx
xor    %eax,%eax
cmp    %ecx,%ebx
jne    116a <sametree+0x4a>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sametree(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 47)
%9 = load i8*, i8** %3
%10 = ptrtoint i8* %8 to i64
%11 = ptrtoint i8* %9 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
store i32 %13, i32* %5
%14 = load i8*, i8** %4
%15 = call i8* @strchr(i8* %14, i8 signext 47)
%16 = load i8*, i8** %4
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %2
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32 @strncmp(i8* %25, i8* %26, i32 %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br label %31
31: ; preds = %24, %2
%32 = phi i1 [ false, %2 ], [ %30, %24 ]
%33 = zext i1 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
define i32 @sametree(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = ptrtoint i8* %3 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = trunc i64 %6 to i32
%8 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%9 = ptrtoint i8* %8 to i64
%10 = ptrtoint i8* %1 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = icmp eq i32 %7, %12
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %7)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %14, %2
%19 = phi i32 [ 0, %2 ], [ %17, %14 ]
ret i32 %19
}