#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*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
double *where(double *in, int *select, int n) {
  int i;
  double *out;
  out = (double *)malloc(n * sizeof(double));
  if (out == NULL) {
    printf("Error: failed in memory declaration\n");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    out[i] = in[select[i]];
  }
  return out;
}


x86 assembly (clang, -O0):
<where>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1177 <where+0x47>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ba <where+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117e <where+0x4e>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<where>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11fd <where+0xcd>
test   %r15d,%r15d
jle    11f7 <where+0xc7>
mov    %r15d,%edx
lea    -0x1(%rdx),%rsi
mov    %edx,%r8d
and    $0x3,%r8d
cmp    $0x3,%rsi
jae    1175 <where+0x45>
xor    %esi,%esi
jmp    11c7 <where+0x97>
and    $0xfffffffc,%edx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movslq (%r14,%rsi,4),%rdi
movsd  (%rbx,%rdi,8),%xmm0
movsd  %xmm0,(%rax,%rsi,8)
movslq 0x4(%r14,%rsi,4),%rdi
movsd  (%rbx,%rdi,8),%xmm0
movsd  %xmm0,0x8(%rax,%rsi,8)
movslq 0x8(%r14,%rsi,4),%rdi
movsd  (%rbx,%rdi,8),%xmm0
movsd  %xmm0,0x10(%rax,%rsi,8)
movslq 0xc(%r14,%rsi,4),%rdi
movsd  (%rbx,%rdi,8),%xmm0
movsd  %xmm0,0x18(%rax,%rsi,8)
add    $0x4,%rsi
cmp    %rsi,%rdx
jne    1180 <where+0x50>
test   %r8,%r8
je     11f7 <where+0xc7>
lea    (%rax,%rsi,8),%rdx
lea    (%r14,%rsi,4),%rsi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
movslq (%rsi,%rdi,4),%rcx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%rdx,%rdi,8)
add    $0x1,%rdi
cmp    %rdi,%r8
jne    11e0 <where+0xb0>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Error: failed in memory declaration\0A\00"
define double* @where(double* %0, i32* %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
store double* %0, double** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %8
%15 = load double*, double** %8
%16 = icmp eq double* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
store i32 0, i32* %7
br label %21
21: ; preds = %39, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load double*, double** %4
%27 = load i32*, i32** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %26, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %8
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double %34, double* %38
br label %39
39: ; preds = %25
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %21
42: ; preds = %21
%43 = load double*, double** %8
ret double* %43
}

LLVM IR (-O2):
@str = [36 x i8] c"Error: failed in memory declaration\00"
define double* @where(double* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = shl i32 %2, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to double*
%7 = icmp eq i64 %5, 0
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %68
10: ; preds = %8
%11 = zext i32 %2 to i64
%12 = add nsw i64 %11, -1
%13 = and i64 %11, 3
%14 = icmp ult i64 %12, 3
br i1 %14, label %53, label %15
15: ; preds = %10
%16 = and i64 %11, 4294967292
br label %20
17: ; preds = %3
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %20, %15
%21 = phi i64 [ 0, %15 ], [ %50, %20 ]
%22 = phi i64 [ 0, %15 ], [ %51, %20 ]
%23 = getelementptr inbounds i32, i32* %1, i64 %21
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %6, i64 %21
store double %27, double* %28
%29 = or i64 %21, 1
%30 = getelementptr inbounds i32, i32* %1, i64 %29
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = getelementptr inbounds double, double* %6, i64 %29
store double %34, double* %35
%36 = or i64 %21, 2
%37 = getelementptr inbounds i32, i32* %1, i64 %36
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %0, i64 %39
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %6, i64 %36
store double %41, double* %42
%43 = or i64 %21, 3
%44 = getelementptr inbounds i32, i32* %1, i64 %43
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %0, i64 %46
%48 = load double, double* %47
%49 = getelementptr inbounds double, double* %6, i64 %43
store double %48, double* %49
%50 = add nuw nsw i64 %21, 4
%51 = add i64 %22, 4
%52 = icmp eq i64 %51, %16
br i1 %52, label %53, label %20
53: ; preds = %20, %10
%54 = phi i64 [ 0, %10 ], [ %50, %20 ]
%55 = icmp eq i64 %13, 0
br i1 %55, label %68, label %56
56: ; preds = %53, %56
%57 = phi i64 [ %65, %56 ], [ %54, %53 ]
%58 = phi i64 [ %66, %56 ], [ 0, %53 ]
%59 = getelementptr inbounds i32, i32* %1, i64 %57
%60 = load i32, i32* %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %0, i64 %61
%63 = load double, double* %62
%64 = getelementptr inbounds double, double* %6, i64 %57
store double %63, double* %64
%65 = add nuw nsw i64 %57, 1
%66 = add i64 %58, 1
%67 = icmp eq i64 %66, %13
br i1 %67, label %68, label %56
68: ; preds = %53, %56, %8
ret double* %6
}