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

/* Variables and functions */
int EXIT_SUCCESS;
int lookup_os(char *, char const **, int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  char const *unixos[] = {"OpenBSD", "FreeBSD", "Debian", "Gentoo",
                          "Arch",    "Solaris", NULL};
  int res = lookup_os("Solaris", unixos, (sizeof(unixos) / sizeof(unixos[0])));
  if (res != -1)
    printf("%s\n", unixos[res]);
  else
    puts("That OS is not in the list, sorry.");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe94(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8c(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x7,%edx
call   1060 <lookup_os@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
je     11dd <main+0x9d>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
jmp    11e9 <main+0xa9>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
movq   $0x0,0x30(%rsp)
lea    0xebc(%rip),%rax
mov    %rax,(%rsp)
lea    0xeb9(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xeb5(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xeb0(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xeab(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xea4(%rip),%rdi
mov    %rdi,0x28(%rsp)
mov    %rsp,%rsi
mov    $0x7,%edx
call   1050 <lookup_os@plt>
cmp    $0xffffffff,%eax
je     11aa <main+0x7a>
cltq
mov    (%rsp,%rax,8),%rsi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
jmp    11b6 <main+0x86>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"OpenBSD\00"
@.str.1 = [8 x i8] c"FreeBSD\00"
@.str.2 = [7 x i8] c"Debian\00"
@.str.3 = [7 x i8] c"Gentoo\00"
@.str.4 = [5 x i8] c"Arch\00"
@.str.5 = [8 x i8] c"Solaris\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [35 x i8] c"That OS is not in the list, sorry.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [7 x i8*]* %2 to i8*
%5 = bitcast i8* %4 to [7 x i8*]*
%6 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8** %6
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i32 0, i32 5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 0
%13 = call i32 @lookup_os(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %12, i32 7)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %0
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %20)
br label %24
22: ; preds = %0
%23 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}

LLVM IR (-O2):
@.str = [8 x i8] c"OpenBSD\00"
@.str.1 = [8 x i8] c"FreeBSD\00"
@.str.2 = [7 x i8] c"Debian\00"
@.str.3 = [7 x i8] c"Gentoo\00"
@.str.4 = [5 x i8] c"Arch\00"
@.str.5 = [8 x i8] c"Solaris\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [35 x i8] c"That OS is not in the list, sorry.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [7 x i8*]
%2 = bitcast [7 x i8*]* %1 to i8*
%3 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 6
%4 = bitcast i8** %3 to i64*
store i64 0, i64* %4
%5 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %10
%11 = call i32 @lookup_os(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %5, i32 7)
%12 = icmp eq i32 %11, -1
br i1 %12, label %18, label %13
13: ; preds = %0
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %1, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}