#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 helper_random_int_min_max(int /*<<< orphan*/, int);
char *companies_get_name(char *names[], int type_idx) {
  static int used_names[4][1000];
  int lookup_name = 1, r;
  do {
    r = helper_random_int_min_max(0, 1000);
    if (used_names[type_idx][r] != 1) {
      used_names[type_idx][r] = 1;
      return names[r];
      lookup_name = 0;
    }
  } while (lookup_name == 1);
  return NULL;
}


x86 assembly (clang, -O0):
<companies_get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
xor    %edi,%edi
mov    $0x3e8,%esi
call   1030 <helper_random_int_min_max@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x14(%rbp),%rcx
lea    0x2f00(%rip),%rax
imul   $0xfa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
je     118d <companies_get_name+0x7d>
movslq -0x14(%rbp),%rcx
lea    0x2edd(%rip),%rax
imul   $0xfa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <companies_get_name+0x94>
jmp    1192 <companies_get_name+0x82>
cmpl   $0x1,-0x18(%rbp)
je     1126 <companies_get_name+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<companies_get_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%rax
imul   $0xfa0,%rax,%rax
lea    0x2f18(%rip),%rbx
add    %rax,%rbx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    $0x3e8,%esi
call   1030 <helper_random_int_min_max@plt>
cltq
cmpl   $0x1,(%rbx,%rax,4)
je     1130 <companies_get_name+0x20>
lea    (%rbx,%rax,4),%rcx
movl   $0x1,(%rcx)
mov    (%r14,%rax,8),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@companies_get_name.used_names = internal global [4 x [1000 x i32]] zeroinitializer
define i8* @companies_get_name(i8** %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 1, i32* %6
br label %8
8: ; preds = %31, %2
%9 = call i32 @helper_random_int_min_max(i32 0, i32 1000)
store i32 %9, i32* %7
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4 x [1000 x i32]], [4 x [1000 x i32]]* @companies_get_name.used_names, i64 0, i64 %11
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000 x i32], [1000 x i32]* %12, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %30
18: ; preds = %8
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x [1000 x i32]], [4 x [1000 x i32]]* @companies_get_name.used_names, i64 0, i64 %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1000 x i32], [1000 x i32]* %21, i64 0, i64 %23
store i32 1, i32* %24
%25 = load i8**, i8*** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
store i8* %29, i8** %3
br label %35
30: ; preds = %8
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 1
br i1 %33, label %8, label %34
34: ; preds = %31
store i8* null, i8** %3
br label %35
35: ; preds = %34, %18
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@companies_get_name.used_names = internal unnamed_addr global [4 x [1000 x i32]] zeroinitializer
define i8* @companies_get_name(i8** nocapture %0, i32 %1) {
%3 = sext i32 %1 to i64
br label %4
4: ; preds = %4, %2
%5 = tail call i32 @helper_random_int_min_max(i32 0, i32 1000)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [4 x [1000 x i32]], [4 x [1000 x i32]]* @companies_get_name.used_names, i64 0, i64 %3, i64 %6
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 1
br i1 %9, label %4, label %10
10: ; preds = %4
store i32 1, i32* %7
%11 = getelementptr inbounds i8*, i8** %0, i64 %6
%12 = load i8*, i8** %11
ret i8* %12
}