#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 omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int, int);
int psum(int *a, int *p, int n) {
  printf("[%d]: %d\n", omp_get_thread_num(), n);
  int *e;
  for (e = a + n, *p = *a++; a < e; a++, p++)
    p[1] = p[0] + a[0];
}


x86 assembly (clang, -O0):
<psum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b3 <psum+0x93>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <psum+0x55>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psum>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
lea    0xec6(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    (%rbx),%eax
mov    %eax,(%r14)
cmp    $0x2,%ebp
jl     1172 <psum+0x52>
movslq %ebp,%rcx
lea    (%rbx,%rcx,4),%rcx
add    $0x4,%rbx
add    $0x4,%r14
nopl   0x0(%rax)
add    (%rbx),%eax
mov    %eax,(%r14)
add    $0x4,%rbx
add    $0x4,%r14
cmp    %rcx,%rbx
jb     1160 <psum+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"[%d]: %d\0A\00"
define i32 @psum(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = call i32 (...) @omp_get_thread_num()
%10 = load i32, i32* %7
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32*, i32** %5
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32* %15, i32** %8
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %5
%18 = load i32, i32* %16
%19 = load i32*, i32** %6
store i32 %18, i32* %19
br label %20
20: ; preds = %34, %3
%21 = load i32*, i32** %5
%22 = load i32*, i32** %8
%23 = icmp ult i32* %21, %22
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = add nsw i32 %27, %30
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 1
store i32 %31, i32* %33
br label %34
34: ; preds = %24
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %5
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i32 1
store i32* %38, i32** %6
br label %20
39: ; preds = %20
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"[%d]: %d\0A\00"
define i32 @psum(i32* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 (...) @omp_get_thread_num()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %2)
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %0
store i32 %8, i32* %1
%9 = icmp sgt i32 %2, 1
br i1 %9, label %10, label %21
10: ; preds = %3
%11 = getelementptr inbounds i32, i32* %0, i64 1
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ %17, %12 ], [ %8, %10 ]
%14 = phi i32* [ %19, %12 ], [ %11, %10 ]
%15 = phi i32* [ %18, %12 ], [ %1, %10 ]
%16 = load i32, i32* %14
%17 = add nsw i32 %16, %13
%18 = getelementptr inbounds i32, i32* %15, i64 1
store i32 %17, i32* %18
%19 = getelementptr inbounds i32, i32* %14, i64 1
%20 = icmp ult i32* %19, %7
br i1 %20, label %12, label %21
21: ; preds = %12, %3
ret i32 undef
}