#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*/ getcwd(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
char *strdup(char const *);
char *_findbin(const char *cmd) {
  char *buf;
  if (cmd[0] == '/') {
    buf = strdup(cmd);
  } else {
    buf = (char *)malloc(1024);
    getcwd(buf, 1024);
    strcat(buf, "/");
    strcat(buf, cmd);
  }
  return buf;
}


x86 assembly (clang, -O0):
<_findbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116e <_findbin+0x2e>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    11a7 <_findbin+0x67>
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   1030 <getcwd@plt>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_findbin>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
jne    115b <_findbin+0x1b>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strdup@plt>
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x400,%esi
call   1030 <getcwd@plt>
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @_findbin(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 47
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %3
br label %22
12: ; preds = %1
%13 = call i64 @malloc(i32 1024)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @getcwd(i8* %15, i32 1024)
%17 = load i8*, i8** %3
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = call i32 @strcat(i8* %19, i8* %20)
br label %22
22: ; preds = %12, %9
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @_findbin(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %12
6: ; preds = %1
%7 = tail call i64 @malloc(i32 1024)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @getcwd(i8* %8, i32 1024)
%10 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strcat(i8* %8, i8* %0)
br label %12
12: ; preds = %6, %4
%13 = phi i8* [ %5, %4 ], [ %8, %6 ]
ret i8* %13
}