#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 /*<<< orphan*/ res;

/* Variables and functions */
scalar_t__ STRSTR(char *, char *);
int msystem(int, char *, int, char *);
int /*<<< orphan*/ putfile(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ unlink(char *);
scalar_t__ which(char *, char *, int);
int find_ranlib(char *ranlib, int size, const char *make) {
  char command[128];
  char res[0x10000];
  int rcode;
  if (which("ranlib", ranlib, size))
    return 1;
  unlink("_.a");
  putfile("_.c", "w", "sub(){}\n");
  putfile("_make", "w",
          "_.a:; $(CC) -c _.c\n\t$(AR) cr _.a _.o\n\t$(AR) st _.a\n\techo "
          "SUCCESS\n");
  sprintf(command, "%s -f _make", make);
  rcode = msystem(1, res, sizeof(res), command);
  unlink("_.c");
  unlink("_make");
  unlink("_.a");
  unlink("_.o");
  if (rcode == 0 && STRSTR(res, "SUCCESS")) {
    strcpy(ranlib, "$(AR) st");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_ranlib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100b0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe6c(%rip),%rdi
call   1070 <which@plt>
cmp    $0x0,%rax
je     11af <find_ranlib+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <find_ranlib+0x136>
lea    0xe51(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe49(%rip),%rdi
lea    0xe46(%rip),%rsi
lea    0xe41(%rip),%rdx
call   1050 <putfile@plt>
lea    0xe86(%rip),%rdi
lea    0xe2c(%rip),%rsi
lea    0xe30(%rip),%rdx
call   1050 <putfile@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x100a0(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
mov    $0x1,%edi
mov    $0x10000,%edx
call   1080 <msystem@plt>
mov    %eax,-0x100a4(%rbp)
lea    0xddb(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe26(%rip),%rdi
call   1030 <unlink@plt>
lea    0xdbf(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe14(%rip),%rdi
call   1030 <unlink@plt>
cmpl   $0x0,-0x100a4(%rbp)
jne    129f <find_ranlib+0x12f>
lea    -0x100a0(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1060 <STRSTR@plt>
cmp    $0x0,%rax
je     129f <find_ranlib+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <find_ranlib+0x136>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ranlib>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10088,%rsp
mov    %rdx,%rbx
mov    %esi,%edx
mov    %rdi,%r15
lea    0xe70(%rip),%rdi
mov    %r15,%rsi
call   1070 <which@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1276 <find_ranlib+0x106>
lea    0xe5a(%rip),%r14
mov    %r14,%rdi
call   1030 <unlink@plt>
lea    0xe4f(%rip),%r12
lea    0xe4c(%rip),%rbp
lea    0xe47(%rip),%rdx
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <putfile@plt>
lea    0xe86(%rip),%r13
lea    0xe37(%rip),%rdx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1050 <putfile@plt>
lea    0xe67(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
lea    0x80(%rsp),%rsi
mov    $0x1,%edi
mov    $0x10000,%edx
mov    %rbp,%rcx
call   1080 <msystem@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    %r13,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
lea    0xe2a(%rip),%rdi
call   1030 <unlink@plt>
xor    %ebp,%ebp
test   %ebx,%ebx
jne    1276 <find_ranlib+0x106>
lea    0xe1c(%rip),%rsi
lea    0x80(%rsp),%rdi
call   1060 <STRSTR@plt>
test   %rax,%rax
je     1276 <find_ranlib+0x106>
lea    0xe0b(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10088,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ranlib\00"
@.str.1 = [4 x i8] c"_.a\00"
@.str.2 = [4 x i8] c"_.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [9 x i8] c"sub(){}\0A\00"
@.str.5 = [6 x i8] c"_make\00"
@.str.6 = [66 x i8] c"_.a:; $(CC) -c _.c\0A\09$(AR) cr _.a _.o\0A\09$(AR) st _.a\0A\09echo SUCCESS\0A\00"
@.str.7 = [12 x i8] c"%s -f _make\00"
@.str.8 = [4 x i8] c"_.o\00"
@.str.9 = [8 x i8] c"SUCCESS\00"
@.str.10 = [9 x i8] c"$(AR) st\00"
define i32 @find_ranlib(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca [65536 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i64 @which(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 1, i32* %4
br label %40
16: ; preds = %3
%17 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @putfile(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @putfile(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0))
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i32 @msystem(i32 1, i8* %23, i32 65536, i8* %24)
store i32 %25, i32* %10
%26 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @unlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%30 = load i32, i32* %10
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %16
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %9, i64 0, i64 0
%34 = call i64 @STRSTR(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i8*, i8** %5
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %4
br label %40
39: ; preds = %32, %16
store i32 0, i32* %4
br label %40
40: ; preds = %39, %36, %15
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [7 x i8] c"ranlib\00"
@.str.1 = [4 x i8] c"_.a\00"
@.str.2 = [4 x i8] c"_.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [9 x i8] c"sub(){}\0A\00"
@.str.5 = [6 x i8] c"_make\00"
@.str.6 = [66 x i8] c"_.a:; $(CC) -c _.c\0A\09$(AR) cr _.a _.o\0A\09$(AR) st _.a\0A\09echo SUCCESS\0A\00"
@.str.7 = [12 x i8] c"%s -f _make\00"
@.str.8 = [4 x i8] c"_.o\00"
@.str.9 = [8 x i8] c"SUCCESS\00"
@.str.10 = [9 x i8] c"$(AR) st\00"
define i32 @find_ranlib(i8* %0, i32 %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca [65536 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%8 = tail call i64 @which(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %3
%11 = tail call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @putfile(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @putfile(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%15 = call i32 @msystem(i32 1, i8* %7, i32 65536, i8* %6)
%16 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @unlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%20 = icmp eq i32 %15, 0
br i1 %20, label %21, label %26
21: ; preds = %10
%22 = call i64 @STRSTR(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %26
26: ; preds = %10, %21, %3, %24
%27 = phi i32 [ 1, %24 ], [ 1, %3 ], [ 0, %21 ], [ 0, %10 ]
ret i32 %27
}