#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*/ free(char *);
int getBinaryPathBuffer(char *, int);
char *malloc(int);
char *getBinaryPath() {
  int len = 0;
  int finalLen = 0;
  char *binPath = NULL;
  do {
    len += 2;
    if (binPath)
      free(binPath);
    binPath = malloc(len * sizeof(char));
  } while ((finalLen = getBinaryPathBuffer(binPath, len)) >= len);
  binPath[finalLen] = '\0';
  return binPath;
}


x86 assembly (clang, -O0):
<getBinaryPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <getBinaryPath+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <getBinaryPathBuffer@plt>
mov    %eax,-0x8(%rbp)
cmp    -0x4(%rbp),%eax
jge    114e <getBinaryPath+0x1e>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBinaryPath>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%ebx
xor    %r14d,%r14d
jmp    115d <getBinaryPath+0x2d>
xchg   %ax,%ax
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1050 <getBinaryPathBuffer@plt>
lea    0x2(%rbx),%ecx
cmp    %ebx,%eax
mov    %ecx,%ebx
jl     116c <getBinaryPath+0x3c>
test   %r14,%r14
je     1140 <getBinaryPath+0x10>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1140 <getBinaryPath+0x10>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @getBinaryPath() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i8* null, i8** %3
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 2
store i32 %6, i32* %1
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %3
%11 = call i32 @free(i8* %10)
br label %12
12: ; preds = %9, %4
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %3
br label %18
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = load i32, i32* %1
%21 = call i32 @getBinaryPathBuffer(i8* %19, i32 %20)
store i32 %21, i32* %2
%22 = load i32, i32* %1
%23 = icmp sge i32 %21, %22
br i1 %23, label %4, label %24
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @getBinaryPath() {
br label %1
1: ; preds = %8, %0
%2 = phi i32 [ 0, %0 ], [ %4, %8 ]
%3 = phi i8* [ null, %0 ], [ %9, %8 ]
%4 = add nuw nsw i32 %2, 2
%5 = icmp eq i8* %3, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @free(i8* %3)
br label %8
8: ; preds = %6, %1
%9 = tail call i8* @malloc(i32 %4)
%10 = tail call i32 @getBinaryPathBuffer(i8* %9, i32 %4)
%11 = icmp slt i32 %10, %4
br i1 %11, label %12, label %1
12: ; preds = %8
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
store i8 0, i8* %14
ret i8* %9
}