#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*/ checkStringParameter(char const *, unsigned int *);
void getSystemBasePath(const char *path, unsigned int pathLength,
                       unsigned int *subLength) {
  static const char *systemPaths[] = {
      "/usr/bin/",         "/usr/lib/",         "/usr/lib32/",
      "/usr/lib64/",       "/usr/local/bin/",   "/usr/local/lib/",
      "/usr/local/lib32/", "/usr/local/lib64/",
  };
  static unsigned char systemPathLengths[] = {9, 11, 15, 17};
  static unsigned char systemPathPrefixLength[] = {5, 11};
  if (!checkStringParameter(path, subLength)) {
    return;
  }
  for (int i = 0; i < 8; ++i) {
    const char *systemPath = systemPaths[i];
    unsigned char systemPathLength = systemPathLengths[i >> 1];
    const char *iter = path + pathLength - 1;
    const char *resetSearchIter = systemPath + systemPathLength - 1;
    const char *searchIter = resetSearchIter;
    while (searchIter >= systemPath && iter >= path) {
      searchIter = *iter == *searchIter ? searchIter - 1 : resetSearchIter;
      --iter;
    }
    if (searchIter < systemPath) {
      *subLength =
          (unsigned int)(iter - path) + systemPathPrefixLength[i >> 2] + 1;
      return;
    }
  }
  *subLength = 0;
}


x86 assembly (clang, -O0):
<getSystemBasePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <checkStringParameter@plt>
cmp    $0x0,%eax
jne    113e <getSystemBasePath+0x2e>
jmp    127d <getSystemBasePath+0x16d>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1273 <getSystemBasePath+0x163>
movslq -0x1c(%rbp),%rcx
lea    0x2ed6(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
movslq %eax,%rcx
lea    0x2efe(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movzbl -0x29(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    -0x28(%rbp),%rcx
mov    %al,-0x49(%rbp)
jb     11c9 <getSystemBasePath+0xb9>
mov    -0x38(%rbp),%rax
cmp    -0x8(%rbp),%rax
setae  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11d9 <getSystemBasePath+0xc9>
jmp    1221 <getSystemBasePath+0x111>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    -0x48(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1200 <getSystemBasePath+0xf0>
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
jmp    1208 <getSystemBasePath+0xf8>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    11a8 <getSystemBasePath+0x98>
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1260 <getSystemBasePath+0x150>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sar    $0x2,%eax
movslq %eax,%rdx
lea    0x2e28(%rip),%rax
movzbl (%rax,%rdx,1),%eax
add    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    127d <getSystemBasePath+0x16d>
jmp    1265 <getSystemBasePath+0x155>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <getSystemBasePath+0x35>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSystemBasePath>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1030 <checkStringParameter@plt>
test   %eax,%eax
je     11e2 <getSystemBasePath+0xd2>
mov    %ebp,%eax
lea    (%rbx,%rax,1),%r10
add    $0xffffffffffffffff,%r10
xor    %ebp,%ebp
lea    0x2ca1(%rip),%r8
lea    0xf2a(%rip),%r9
cs nopw 0x0(%rax,%rax,1)
mov    (%r8,%rbp,8),%rdi
mov    %ebp,%ecx
shr    %ecx
movzbl (%rcx,%r9,1),%ecx
lea    (%rdi,%rcx,1),%rsi
add    $0xffffffffffffffff,%rsi
cmp    %rdi,%rsi
jb     11b0 <getSystemBasePath+0xa0>
cmp    %rbx,%r10
jb     11b0 <getSystemBasePath+0xa0>
mov    %r10,%rcx
mov    %rsi,%rdx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rcx),%eax
cmp    (%rdx),%al
je     1190 <getSystemBasePath+0x80>
mov    %rsi,%rdx
jmp    1194 <getSystemBasePath+0x84>
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rdx
add    $0xffffffffffffffff,%rcx
cmp    %rdi,%rdx
jb     11b6 <getSystemBasePath+0xa6>
cmp    %rbx,%rcx
jae    1180 <getSystemBasePath+0x70>
jmp    11b6 <getSystemBasePath+0xa6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rsi,%rdx
mov    %r10,%rcx
cmp    %rdi,%rdx
jb     11c9 <getSystemBasePath+0xb9>
add    $0x1,%rbp
cmp    $0x8,%rbp
jne    1150 <getSystemBasePath+0x40>
xor    %eax,%eax
jmp    11df <getSystemBasePath+0xcf>
sub    %ebx,%ecx
shr    $0x2,%ebp
lea    0xe9f(%rip),%rax
movzbl 0x0(%rbp,%rax,1),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@getSystemBasePath.systemPaths = internal global [8 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i32 0, i32 0)]
@.str = [10 x i8] c"/usr/bin/\00"
@.str.1 = [10 x i8] c"/usr/lib/\00"
@.str.2 = [12 x i8] c"/usr/lib32/\00"
@.str.3 = [12 x i8] c"/usr/lib64/\00"
@.str.4 = [16 x i8] c"/usr/local/bin/\00"
@.str.5 = [16 x i8] c"/usr/local/lib/\00"
@.str.6 = [18 x i8] c"/usr/local/lib32/\00"
@.str.7 = [18 x i8] c"/usr/local/lib64/\00"
@getSystemBasePath.systemPathLengths = internal global [4 x i8] c"\09\0B\0F\11"
@getSystemBasePath.systemPathPrefixLength = internal global [2 x i8] c"\05\0B"
define void @getSystemBasePath(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%13 = load i8*, i8** %4
%14 = load i32*, i32** %6
%15 = call i32 @checkStringParameter(i8* %13, i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %3
br label %97
18: ; preds = %3
store i32 0, i32* %7
br label %19
19: ; preds = %92, %18
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 8
br i1 %21, label %22, label %95
22: ; preds = %19
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i8*], [8 x i8*]* @getSystemBasePath.systemPaths, i64 0, i64 %24
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i32, i32* %7
%28 = ashr i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4 x i8], [4 x i8]* @getSystemBasePath.systemPathLengths, i64 0, i64 %29
%31 = load i8, i8* %30
store i8 %31, i8* %9
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -1
store i8* %36, i8** %10
%37 = load i8*, i8** %8
%38 = load i8, i8* %9
%39 = zext i8 %38 to i32
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -1
store i8* %42, i8** %11
%43 = load i8*, i8** %11
store i8* %43, i8** %12
br label %44
44: ; preds = %67, %22
%45 = load i8*, i8** %12
%46 = load i8*, i8** %8
%47 = icmp uge i8* %45, %46
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i8*, i8** %10
%50 = load i8*, i8** %4
%51 = icmp uge i8* %49, %50
br label %52
52: ; preds = %48, %44
%53 = phi i1 [ false, %44 ], [ %51, %48 ]
br i1 %53, label %54, label %71
54: ; preds = %52
%55 = load i8*, i8** %10
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = load i8*, i8** %12
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %57, %60
br i1 %61, label %62, label %65
62: ; preds = %54
%63 = load i8*, i8** %12
%64 = getelementptr inbounds i8, i8* %63, i64 -1
br label %67
65: ; preds = %54
%66 = load i8*, i8** %11
br label %67
67: ; preds = %65, %62
%68 = phi i8* [ %64, %62 ], [ %66, %65 ]
store i8* %68, i8** %12
%69 = load i8*, i8** %10
%70 = getelementptr inbounds i8, i8* %69, i32 -1
store i8* %70, i8** %10
br label %44
71: ; preds = %52
%72 = load i8*, i8** %12
%73 = load i8*, i8** %8
%74 = icmp ult i8* %72, %73
br i1 %74, label %75, label %91
75: ; preds = %71
%76 = load i8*, i8** %10
%77 = load i8*, i8** %4
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = trunc i64 %80 to i32
%82 = load i32, i32* %7
%83 = ashr i32 %82, 2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [2 x i8], [2 x i8]* @getSystemBasePath.systemPathPrefixLength, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = add i32 %81, %87
%89 = add i32 %88, 1
%90 = load i32*, i32** %6
store i32 %89, i32* %90
br label %97
91: ; preds = %71
br label %92
92: ; preds = %91
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
br label %19
95: ; preds = %19
%96 = load i32*, i32** %6
store i32 0, i32* %96
br label %97
97: ; preds = %95, %75, %17
ret void
}

LLVM IR (-O2):
@getSystemBasePath.systemPaths = internal unnamed_addr constant [8 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i32 0, i32 0)]
@.str = [10 x i8] c"/usr/bin/\00"
@.str.1 = [10 x i8] c"/usr/lib/\00"
@.str.2 = [12 x i8] c"/usr/lib32/\00"
@.str.3 = [12 x i8] c"/usr/lib64/\00"
@.str.4 = [16 x i8] c"/usr/local/bin/\00"
@.str.5 = [16 x i8] c"/usr/local/lib/\00"
@.str.6 = [18 x i8] c"/usr/local/lib32/\00"
@.str.7 = [18 x i8] c"/usr/local/lib64/\00"
@getSystemBasePath.systemPathLengths = internal unnamed_addr constant [4 x i8] c"\09\0B\0F\11"
@getSystemBasePath.systemPathPrefixLength = internal unnamed_addr constant [2 x i8] c"\05\0B"
define void @getSystemBasePath(i8* %0, i32 %1, i32* %2) {
%4 = tail call i32 @checkStringParameter(i8* %0, i32* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %57, label %6
6: ; preds = %3
%7 = zext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = icmp uge i8* %9, %0
br label %11
11: ; preds = %6, %40
%12 = phi i64 [ 0, %6 ], [ %41, %40 ]
%13 = getelementptr inbounds [8 x i8*], [8 x i8*]* @getSystemBasePath.systemPaths, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = lshr i64 %12, 1
%16 = and i64 %15, 2147483647
%17 = getelementptr inbounds [4 x i8], [4 x i8]* @getSystemBasePath.systemPathLengths, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i64
%20 = getelementptr inbounds i8, i8* %14, i64 -1
%21 = getelementptr inbounds i8, i8* %20, i64 %19
%22 = icmp uge i8* %21, %14
%23 = select i1 %22, i1 %10, i1 false
br i1 %23, label %24, label %36
24: ; preds = %11, %24
%25 = phi i8* [ %32, %24 ], [ %9, %11 ]
%26 = phi i8* [ %31, %24 ], [ %21, %11 ]
%27 = load i8, i8* %25
%28 = load i8, i8* %26
%29 = icmp eq i8 %27, %28
%30 = getelementptr inbounds i8, i8* %26, i64 -1
%31 = select i1 %29, i8* %30, i8* %21
%32 = getelementptr inbounds i8, i8* %25, i64 -1
%33 = icmp uge i8* %31, %14
%34 = icmp uge i8* %32, %0
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %24, label %36
36: ; preds = %24, %11
%37 = phi i8* [ %21, %11 ], [ %31, %24 ]
%38 = phi i8* [ %9, %11 ], [ %32, %24 ]
%39 = icmp ult i8* %37, %14
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = add nuw nsw i64 %12, 1
%42 = icmp eq i64 %41, 8
br i1 %42, label %55, label %11
43: ; preds = %36
%44 = ptrtoint i8* %38 to i64
%45 = ptrtoint i8* %0 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
%48 = lshr i64 %12, 2
%49 = and i64 %48, 1073741823
%50 = getelementptr inbounds [2 x i8], [2 x i8]* @getSystemBasePath.systemPathPrefixLength, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = add i32 %47, 1
%54 = add i32 %53, %52
br label %55
55: ; preds = %40, %43
%56 = phi i32 [ %54, %43 ], [ 0, %40 ]
store i32 %56, i32* %2
br label %57
57: ; preds = %55, %3
ret void
}