#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 */
typedef int uint32_t;

/* Variables and functions */
char *extract_simple(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
char *which_command(char *);
uint32_t handle_CheckCommand(char *line) {
  uint32_t ret = 2;
  char *cmdret = NULL;
  if (line[0] == 'C') {
    char *tmp = extract_simple(line);
    printf("[check] existence of command [%s]: ", tmp);
    cmdret = which_command(tmp);
    free(tmp);
    if (cmdret == NULL || strlen(cmdret) == 0) {
      printf("executable not found\n");
      ret = 0;
    } else {
      printf("found at %s\n", cmdret);
      ret = 1;
    }
    if (cmdret != NULL)
      free(cmdret);
  }
  return ret;
}


x86 assembly (clang, -O0):
<handle_CheckCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x43,%eax
jne    121a <handle_CheckCommand+0xca>
mov    -0x8(%rbp),%rdi
call   1070 <extract_simple@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <which_command@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     11ce <handle_CheckCommand+0x7e>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11e8 <handle_CheckCommand+0x98>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1201 <handle_CheckCommand+0xb1>
mov    -0x18(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1215 <handle_CheckCommand+0xc5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    121a <handle_CheckCommand+0xca>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_CheckCommand>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ebp
cmpb   $0x43,(%rdi)
jne    11d3 <handle_CheckCommand+0x83>
call   1070 <extract_simple@plt>
mov    %rax,%rbx
lea    0xe93(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <which_command@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11af <handle_CheckCommand+0x5f>
cmpb   $0x0,(%r14)
je     11bd <handle_CheckCommand+0x6d>
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
jmp    11cb <handle_CheckCommand+0x7b>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
jmp    11d3 <handle_CheckCommand+0x83>
lea    0xe6d(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"[check] existence of command [%s]: \00"
@.str.1 = [22 x i8] c"executable not found\0A\00"
@.str.2 = [13 x i8] c"found at %s\0A\00"
define i32 @handle_CheckCommand(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 2, i32* %3
store i8* null, i8** %4
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 67
br i1 %10, label %11, label %38
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i8* @extract_simple(i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %5
%17 = call i8* @which_command(i8* %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %11
%23 = load i8*, i8** %4
%24 = call i64 @strlen(i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22, %11
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %31
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %31
31: ; preds = %28, %26
%32 = load i8*, i8** %4
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %1
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [36 x i8] c"[check] existence of command [%s]: \00"
@.str.2 = [13 x i8] c"found at %s\0A\00"
@str = [21 x i8] c"executable not found\00"
define i32 @handle_CheckCommand(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 67
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = tail call i8* @extract_simple(i8* %0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i8* @which_command(i8* %5)
%8 = tail call i32 @free(i8* %5)
%9 = icmp eq i8* %7, null
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %22
12: ; preds = %4
%13 = load i8, i8* %7
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %19
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ 1, %15 ], [ 0, %17 ]
%21 = tail call i32 @free(i8* %7)
br label %22
22: ; preds = %10, %19, %1
%23 = phi i32 [ 2, %1 ], [ %20, %19 ], [ 0, %10 ]
ret i32 %23
}