#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 *malloc(size_t const);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *const);
int /*<<< orphan*/ strcpy(char *, char const *const);
size_t const strlen(char const *const);
char *strtok(char *, char *);
char **xa_alloc(int, int /*<<< orphan*/);
int /*<<< orphan*/ xa_extend(char const ***, int);
int xa_size(char const **);
const char *const *getCheckPaths(const char *const argument,
                                 const char *const pathEnv) {
  const size_t argLength = strlen(argument);
  const char **checkPaths = xa_alloc(sizeof(char *), 0);
  char *pathCpy, *currentStr;
  xa_extend(&checkPaths, 1);
  checkPaths[0] = argument;
  pathCpy = malloc(strlen(pathEnv) + 1);
  strcpy(pathCpy, pathEnv);
  currentStr = strtok(pathCpy, ":");
  while (currentStr) {
    char *newPath;
    xa_extend(&checkPaths, 1);
    newPath = malloc(strlen(currentStr) + argLength + 2);
    sprintf(newPath, "%s/%s", currentStr, argument);
    checkPaths[xa_size(checkPaths) - 1] = newPath;
    currentStr = strtok(NULL, ":");
  }
  return checkPaths;
}


x86 assembly (clang, -O0):
<getCheckPaths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x8,%edi
xor    %esi,%esi
call   1050 <xa_alloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <xa_extend@plt>
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1294 <getCheckPaths+0x114>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <xa_extend@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xdb9(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <xa_size@plt>
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7a(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1200 <getCheckPaths+0x80>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCheckPaths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    $0x8,%edi
xor    %esi,%esi
call   1050 <xa_alloc@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   10a0 <xa_extend@plt>
mov    (%rsp),%rax
mov    %r14,(%rax)
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe1d(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1267 <getCheckPaths+0xe7>
mov    %rax,%rbp
add    $0x2,%rbx
lea    0xe04(%rip),%r12
lea    0xdfb(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsp,%rdi
mov    $0x1,%esi
call   10a0 <xa_extend@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1090 <sprintf@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1060 <xa_size@plt>
cltq
mov    %r15,-0x8(%rbp,%rax,8)
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1210 <getCheckPaths+0x90>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8** @getCheckPaths(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %5
%12 = call i8** @xa_alloc(i32 8, i32 0)
store i8** %12, i8*** %6
%13 = call i32 @xa_extend(i8*** %6, i32 1)
%14 = load i8*, i8** %3
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 0
store i8* %14, i8** %16
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = add i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %7
%25 = call i8* @strtok(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %8
br label %26
26: ; preds = %29, %2
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %49
29: ; preds = %26
%30 = call i32 @xa_extend(i8*** %6, i32 1)
%31 = load i8*, i8** %8
%32 = call i64 @strlen(i8* %31)
%33 = load i64, i64* %5
%34 = add i64 %32, %33
%35 = add i64 %34, 2
%36 = call i8* @malloc(i64 %35)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = load i8*, i8** %8
%39 = load i8*, i8** %3
%40 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39)
%41 = load i8*, i8** %9
%42 = load i8**, i8*** %6
%43 = load i8**, i8*** %6
%44 = call i32 @xa_size(i8** %43)
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %42, i64 %46
store i8* %41, i8** %47
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %48, i8** %8
br label %26
49: ; preds = %26
%50 = load i8**, i8*** %6
ret i8** %50
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8** @getCheckPaths(i8* %0, i8* %1) {
%3 = alloca i8**
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = bitcast i8*** %3 to i8*
%6 = tail call i8** @xa_alloc(i32 8, i32 0)
store i8** %6, i8*** %3
%7 = call i32 @xa_extend(i8*** %3, i32 1)
%8 = load i8**, i8*** %3
store i8* %0, i8** %8
%9 = call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %9, 1
%11 = call i8* @malloc(i64 %10)
%12 = call i32 @strcpy(i8* %11, i8* %1)
%13 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %31, label %15
15: ; preds = %2
%16 = add i64 %4, 2
br label %17
17: ; preds = %15, %17
%18 = phi i8* [ %13, %15 ], [ %29, %17 ]
%19 = call i32 @xa_extend(i8*** %3, i32 1)
%20 = call i64 @strlen(i8* %18)
%21 = add i64 %16, %20
%22 = call i8* @malloc(i64 %21)
%23 = call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %0)
%24 = load i8**, i8*** %3
%25 = call i32 @xa_size(i8** %24)
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* %22, i8** %28
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %17
31: ; preds = %17, %2
%32 = load i8**, i8*** %3
ret i8** %32
}