void getBundlePart(const char *fullpath, unsigned int length,
                   unsigned int *newLength) {
  if (newLength == 0x0) {
    return;
  }
  if (fullpath == 0x0 || length == 0) {
    *newLength = 0;
    return;
  }
  const char *potentialBundleStart = fullpath + length - 15;
  if (strncmp(potentialBundleStart, "/Contents/MacOS", 15) != 0) {
    *newLength = 0;
    return;
  }
  *newLength = length - 15;
}


x86 assembly (clang, -O0):
<getBundlePart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1133 <getBundlePart+0x23>
jmp    11a2 <getBundlePart+0x92>
cmpq   $0x0,-0x8(%rbp)
je     1148 <getBundlePart+0x38>
cmpl   $0x0,-0xc(%rbp)
jne    1157 <getBundlePart+0x47>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11a2 <getBundlePart+0x92>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
add    $0xfffffffffffffff1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0xf,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1196 <getBundlePart+0x86>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11a2 <getBundlePart+0x92>
mov    -0xc(%rbp),%ecx
sub    $0xf,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBundlePart>:
test   %rdx,%rdx
je     1154 <getBundlePart+0x44>
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
xor    %ecx,%ecx
test   %rdi,%rdi
je     114c <getBundlePart+0x3c>
mov    %esi,%ebp
test   %esi,%esi
je     114c <getBundlePart+0x3c>
mov    %ebp,%eax
add    %rax,%rdi
add    $0xfffffffffffffff1,%rdi
lea    0xec8(%rip),%rsi
mov    $0xf,%edx
call   1030 <strncmp@plt>
add    $0xfffffff1,%ebp
xor    %ecx,%ecx
test   %eax,%eax
cmove  %ebp,%ecx
mov    %ecx,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/Contents/MacOS\00"
define void @getBundlePart(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
br label %34
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %11
%18 = load i32*, i32** %6
store i32 0, i32* %18
br label %34
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -15
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load i32*, i32** %6
store i32 0, i32* %29
br label %34
30: ; preds = %19
%31 = load i32, i32* %5
%32 = sub i32 %31, 15
%33 = load i32*, i32** %6
store i32 %32, i32* %33
br label %34
34: ; preds = %30, %28, %17, %10
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/Contents/MacOS\00"
define void @getBundlePart(i8* %0, i32 %1, i32* writeonly %2) {
%4 = icmp eq i32* %2, null
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = icmp eq i8* %0, null
%7 = icmp eq i32 %1, 0
%8 = or i1 %6, %7
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = zext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -15
%13 = tail call i32 @strncmp(i8* %12, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15)
%14 = icmp eq i32 %13, 0
%15 = add i32 %1, -15
%16 = select i1 %14, i32 %15, i32 0
br label %17
17: ; preds = %5, %9
%18 = phi i32 [ %16, %9 ], [ 0, %5 ]
store i32 %18, i32* %2
br label %19
19: ; preds = %17, %3
ret void
}