#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 sum(int *);
int /*<<< orphan*/ test_assert(int);
int main(void) {
  int x[4] = {1, 2, 3, 4};
  int temp, i, ret, ret2;
  ret = sum(x);
  temp = x[0];
  for (i = 0; i < 4 - 1; i++) {
    x[i] = x[i + 1];
  }
  x[4 - 1] = temp;
  ret2 = sum(x);
  test_assert(ret == ret2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <sum@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    118a <main+0x6a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x20(%rbp,%rax,4),%ecx
movslq -0x28(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115e <main+0x3e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <sum@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <test_assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movaps 0xed3(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <sum@plt>
mov    %eax,%ebp
mov    (%rsp),%eax
mov    0x4(%rsp),%rcx
mov    0xc(%rsp),%edx
mov    %edx,0x8(%rsp)
mov    %rcx,(%rsp)
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <sum@plt>
xor    %edi,%edi
cmp    %eax,%ebp
sete   %dil
call   1040 <test_assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.main.x = [4 x i32] [i32 1, i32 2, i32 3, i32 4]
define i32 @main() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%4 = call i32 @sum(i32* %3)
%5 = load i32, i32* %3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%7 = bitcast i32* %6 to i8*
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
store i32 %5, i32* %8
%9 = call i32 @sum(i32* %3)
%10 = icmp eq i32 %4, %9
%11 = zext i1 %10 to i32
%12 = call i32 @test_assert(i32 %11)
ret i32 0
}