#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*/ foo(int);
void f(int *p, unsigned int n) {
  foo(*(p + n * 4));
  foo(*(p + 32 + n * 4));
  if (n > 3)
    foo(*(p + 16 + n * 4));
  else
    foo(*(p + 48 + n * 4));
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edi
call   1030 <foo@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
mov    0x80(%rax,%rcx,4),%edi
call   1030 <foo@plt>
cmpl   $0x3,-0xc(%rbp)
jbe    116f <f+0x5f>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
mov    0x40(%rax,%rcx,4),%edi
call   1030 <foo@plt>
jmp    1187 <f+0x77>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
mov    0xc0(%rax,%rcx,4),%edi
call   1030 <foo@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,4),%ebx
mov    (%rdi,%rbx,4),%edi
call   1030 <foo@plt>
mov    0x80(%r15,%rbx,4),%edi
call   1030 <foo@plt>
xor    %eax,%eax
cmp    $0x4,%r14d
setb   %al
shl    $0x7,%rax
add    %r15,%rax
mov    0x40(%rax,%rbx,4),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <foo@plt>

LLVM IR (-O0):
define void @f(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32*, i32** %3
%6 = load i32, i32* %4
%7 = mul i32 %6, 4
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %5, i64 %8
%10 = load i32, i32* %9
%11 = call i32 @foo(i32 %10)
%12 = load i32*, i32** %3
%13 = getelementptr inbounds i32, i32* %12, i64 32
%14 = load i32, i32* %4
%15 = mul i32 %14, 4
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %13, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @foo(i32 %18)
%20 = load i32, i32* %4
%21 = icmp ugt i32 %20, 3
br i1 %21, label %22, label %31
22: ; preds = %2
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 16
%25 = load i32, i32* %4
%26 = mul i32 %25, 4
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
%29 = load i32, i32* %28
%30 = call i32 @foo(i32 %29)
br label %40
31: ; preds = %2
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 48
%34 = load i32, i32* %4
%35 = mul i32 %34, 4
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = load i32, i32* %37
%39 = call i32 @foo(i32 %38)
br label %40
40: ; preds = %31, %22
ret void
}

LLVM IR (-O2):
define void @f(i32* nocapture %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = tail call i32 @foo(i32 %6)
%8 = getelementptr inbounds i32, i32* %0, i64 32
%9 = getelementptr inbounds i32, i32* %8, i64 %4
%10 = load i32, i32* %9
%11 = tail call i32 @foo(i32 %10)
%12 = icmp ugt i32 %1, 3
%13 = select i1 %12, i64 16, i64 48
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = getelementptr inbounds i32, i32* %14, i64 %4
%16 = load i32, i32* %15
%17 = tail call i32 @foo(i32 %16)
ret void
}