#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int EIO;
int PATH_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_colocated_path(char *, char *, char *, int);
scalar_t__ memcmp(char *, char *, scalar_t__);
scalar_t__ simple_io_read_whole_file_zt(char *, char *, int);
int /*<<< orphan*/ stderr;
int test_get_colocated_path(char *argv0) {
  char buf1[4096], buf2[4096], path[PATH_MAX];
  ssize_t buf1_sz, buf2_sz;
  do {
    int __my_ret__ =
        get_colocated_path(argv0, "run_cmd_unit", path, sizeof(path));
    if (__my_ret__) {
      fprintf(
          stderr, "failed on line %d: %s\n", 83,
          "get_colocated_path(argv0, \"run_cmd_unit\", path, sizeof(path))");
      return __my_ret__;
    }
  } while (0);
  ;
  buf1_sz = simple_io_read_whole_file_zt(argv0, buf1, sizeof(buf1));
  if (buf1_sz < 0) {
    fprintf(stderr,
            "test_get_colocated_path: failed to read binary "
            "from '%s'\n",
            argv0);
    return buf1_sz;
  }
  buf2_sz = simple_io_read_whole_file_zt(path, buf2, sizeof(buf2));
  if (buf2_sz < 0) {
    fprintf(stderr,
            "test_get_colocated_path: failed to read binary "
            "from '%s'\n",
            argv0);
    return buf1_sz;
  }
  if ((buf1_sz != buf2_sz) || (memcmp(buf1, buf2, buf1_sz))) {
    fprintf(stderr,
            "test_get_colocated_path: the binaries read "
            "from '%s' and '%s' were not the same.\n",
            argv0, path);
    return -EIO;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_get_colocated_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x2048(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x2018(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2040(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x2020(%rbp)
mov    -0x2040(%rbp),%rdx
mov    -0x2048(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    %eax,%ecx
lea    0xe5a(%rip),%rsi
call   1040 <get_colocated_path@plt>
mov    %eax,-0x2034(%rbp)
cmpl   $0x0,-0x2034(%rbp)
je     11f9 <test_get_colocated_path+0xb9>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x53,%edx
lea    0xe4a(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2034(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2038(%rbp)
jmp    134a <test_get_colocated_path+0x20a>
jmp    11fe <test_get_colocated_path+0xbe>
jmp    1203 <test_get_colocated_path+0xc3>
mov    -0x10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <simple_io_read_whole_file_zt@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x0,-0x2028(%rbp)
jge    1261 <test_get_colocated_path+0x121>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2028(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2038(%rbp)
jmp    134a <test_get_colocated_path+0x20a>
mov    -0x2040(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <simple_io_read_whole_file_zt@plt>
mov    %rax,-0x2030(%rbp)
cmpq   $0x0,-0x2030(%rbp)
jge    12c2 <test_get_colocated_path+0x182>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2028(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2038(%rbp)
jmp    134a <test_get_colocated_path+0x20a>
mov    -0x2028(%rbp),%rax
cmp    -0x2030(%rbp),%rax
jne    12fa <test_get_colocated_path+0x1ba>
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
mov    -0x2028(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1339 <test_get_colocated_path+0x1f9>
mov    -0x2040(%rbp),%rcx
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    0x2cb3(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2038(%rbp)
jmp    134a <test_get_colocated_path+0x20a>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2038(%rbp)
mov    -0x2018(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_colocated_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    %rdi,%r14
mov    %rsp,%r12
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe84(%rip),%rsi
mov    %rbx,%rdx
call   1040 <get_colocated_path@plt>
test   %eax,%eax
je     11b3 <test_get_colocated_path+0x73>
mov    %eax,%r15d
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
lea    0xe82(%rip),%rcx
mov    $0x53,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    124e <test_get_colocated_path+0x10e>
lea    -0x2020(%rbp),%rsi
mov    %r14,%rdi
mov    $0x1000,%edx
call   1030 <simple_io_read_whole_file_zt@plt>
mov    %rax,%r15
test   %rax,%rax
js     1234 <test_get_colocated_path+0xf4>
lea    -0x1020(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x1000,%edx
call   1030 <simple_io_read_whole_file_zt@plt>
test   %rax,%rax
js     1234 <test_get_colocated_path+0xf4>
cmp    %rax,%r15
jne    1208 <test_get_colocated_path+0xc8>
lea    -0x2020(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    %r15,%rdx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1261 <test_get_colocated_path+0x121>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2da9(%rip),%rax
sub    (%rax),%r15d
jmp    124e <test_get_colocated_path+0x10e>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rsp
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
jmp    124e <test_get_colocated_path+0x10e>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [13 x i8] c"run_cmd_unit\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [62 x i8] c"get_colocated_path(argv0, \22run_cmd_unit\22, path, sizeof(path))\00"
@.str.3 = [58 x i8] c"test_get_colocated_path: failed to read binary from '%s'\0A\00"
@.str.4 = [82 x i8] c"test_get_colocated_path: the binaries read from '%s' and '%s' were not the same.\0A\00"
@EIO = global i32 0
define i32 @test_get_colocated_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
br label %16
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = trunc i64 %13 to i32
%19 = call i32 @get_colocated_path(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 83, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %10
store i32 %25, i32* %2
store i32 1, i32* %11
br label %68
26: ; preds = %16
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
%29 = load i8*, i8** %3
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%31 = call i64 @simple_io_read_whole_file_zt(i8* %29, i8* %30, i32 4096)
store i64 %31, i64* %8
%32 = load i64, i64* %8
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %3
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i64, i64* %8
%39 = trunc i64 %38 to i32
store i32 %39, i32* %2
store i32 1, i32* %11
br label %68
40: ; preds = %28
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%42 = call i64 @simple_io_read_whole_file_zt(i8* %15, i8* %41, i32 4096)
store i64 %42, i64* %9
%43 = load i64, i64* %9
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i64, i64* %8
%50 = trunc i64 %49 to i32
store i32 %50, i32* %2
store i32 1, i32* %11
br label %68
51: ; preds = %40
%52 = load i64, i64* %8
%53 = load i64, i64* %9
%54 = icmp ne i64 %52, %53
br i1 %54, label %61, label %55
55: ; preds = %51
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%58 = load i64, i64* %8
%59 = call i64 @memcmp(i8* %56, i8* %57, i64 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %55, %51
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %3
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0), i8* %63, i8* %15)
%65 = load i32, i32* @EIO
%66 = sub nsw i32 0, %65
store i32 %66, i32* %2
store i32 1, i32* %11
br label %68
67: ; preds = %55
store i32 0, i32* %2
store i32 1, i32* %11
br label %68
68: ; preds = %67, %61, %45, %34, %22
%69 = load i8*, i8** %6
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [13 x i8] c"run_cmd_unit\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [62 x i8] c"get_colocated_path(argv0, \22run_cmd_unit\22, path, sizeof(path))\00"
@.str.3 = [58 x i8] c"test_get_colocated_path: failed to read binary from '%s'\0A\00"
@.str.4 = [82 x i8] c"test_get_colocated_path: the binaries read from '%s' and '%s' were not the same.\0A\00"
@EIO = global i32 0
define i32 @test_get_colocated_path(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = call i32 @get_colocated_path(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 83, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
br label %39
15: ; preds = %1
%16 = call i64 @simple_io_read_whole_file_zt(i8* %0, i8* %4, i32 4096)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%21 = trunc i64 %16 to i32
br label %39
22: ; preds = %15
%23 = call i64 @simple_io_read_whole_file_zt(i8* %9, i8* %5, i32 4096)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%28 = trunc i64 %16 to i32
br label %39
29: ; preds = %22
%30 = icmp eq i64 %16, %23
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = call i64 @memcmp(i8* %4, i8* %5, i64 %16)
%33 = icmp eq i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %31, %29
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %9)
%37 = load i32, i32* @EIO
%38 = sub nsw i32 0, %37
br label %39
39: ; preds = %12, %31, %34, %25, %18
%40 = phi i32 [ %21, %18 ], [ %28, %25 ], [ %38, %34 ], [ %10, %12 ], [ 0, %31 ]
ret i32 %40
}