#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*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ my_strlen(char *);
char *strcatrealloc(char *, char *, int /*<<< orphan*/);
char *path_no_path(char *path, char *cmd, int *ok) {
  if (cmd == NULL)
    return (NULL);
  if (access(cmd, X_OK) == 0) {
    if ((path = strcatrealloc(path, cmd, my_strlen(cmd))) == NULL)
      return (NULL);
    *ok = 0;
  }
  return (path);
}


x86 assembly (clang, -O0):
<path_no_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115c <path_no_path+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11cd <path_no_path+0x9d>
mov    -0x18(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11c5 <path_no_path+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <strcatrealloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11bb <path_no_path+0x8b>
movq   $0x0,-0x8(%rbp)
jmp    11cd <path_no_path+0x9d>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_no_path>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     117f <path_no_path+0x4f>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %rax,%rax
jne    1182 <path_no_path+0x52>
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strcatrealloc@plt>
test   %rax,%rax
je     117f <path_no_path+0x4f>
mov    %rax,%r15
movl   $0x0,(%r14)
jmp    1182 <path_no_path+0x52>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@X_OK = global i32 0
define i8* @path_no_path(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i8*, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i8* null, i8** %4
br label %28
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = load i32, i32* @X_OK
%14 = call i64 @access(i8* %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 @my_strlen(i8* %19)
%21 = call i8* @strcatrealloc(i8* %17, i8* %18, i32 %20)
store i8* %21, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %16
store i8* null, i8** %4
br label %28
24: ; preds = %16
%25 = load i32*, i32** %7
store i32 0, i32* %25
br label %26
26: ; preds = %24, %11
%27 = load i8*, i8** %5
store i8* %27, i8** %4
br label %28
28: ; preds = %26, %23, %10
%29 = load i8*, i8** %4
ret i8* %29
}

LLVM IR (-O2):
@X_OK = global i32 0
define i8* @path_no_path(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = load i32, i32* @X_OK
%7 = tail call i64 @access(i8* %1, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = tail call i32 @my_strlen(i8* %1)
%11 = tail call i8* @strcatrealloc(i8* %0, i8* %1, i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 0, i32* %2
br label %14
14: ; preds = %5, %13, %9, %3
%15 = phi i8* [ null, %3 ], [ null, %9 ], [ %11, %13 ], [ %0, %5 ]
ret i8* %15
}