#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int *a;
  int n = 2, nthreads, vlen, indx, offset = 4, i, TID;
  int failed;
  indx = offset;
#pragma omp parallel firstprivate(indx) shared(a, n, nthreads, failed)
  {
#pragma omp single
    {
      nthreads = 1;
      vlen = indx + n * nthreads;
      if ((a = (int *)malloc(vlen * sizeof(int))) == NULL)
        failed = 1;
      else
        failed = 0;
    }
  }
  if (failed == 1) {
    printf("Fatal error: memory allocation for a failed vlen = %d\n", vlen);
    return (-1);
  } else {
    printf("Diagnostics:\n");
    printf("nthreads = %d\n", nthreads);
    printf("indx     = %d\n", indx);
    printf("n        = %d\n", n);
    printf("vlen     = %d\n", vlen);
  }
  for (i = 0; i < vlen; i++)
    a[i] = -i - 1;
  printf("Length of segment per thread is %d\n", n);
  printf("Offset for vector a is %d\n", indx);
#pragma omp parallel default(none) private(i, TID, indx) shared(n, offset, a)
  {
    TID = 0;
    indx = offset + n * TID;
    for (i = indx; i < indx + n; i++)
      a[i] = TID + 1;
  }
  printf("After the parallel region:\n");
  for (i = 0; i < vlen; i++)
    printf("a[%d] = %d\n", i, a[i]);
  free(a);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1192 <main+0x62>
movl   $0x1,-0x30(%rbp)
jmp    1199 <main+0x69>
movl   $0x0,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    11c0 <main+0x90>
mov    -0x1c(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <main+0x1df>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1246 <main+0x116>
xor    %edx,%edx
sub    -0x28(%rbp),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1219 <main+0xe9>
mov    -0x14(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    12b4 <main+0x184>
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1284 <main+0x154>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ff <main+0x1cf>
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12c9 <main+0x199>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x18,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1286 <main+0x146>
mov    %rax,%rbx
lea    0xf6d(%rip),%rdi
call   1040 <puts@plt>
lea    0xeda(%rip),%rdi
xor    %r14d,%r14d
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed3(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movaps 0xe44(%rip),%xmm0
movups %xmm0,(%rbx)
movabs $0xfffffffafffffffb,%rax
ff ff ff
mov    %rax,0x10(%rbx)
lea    0xeaf(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movabs $0x100000001,%rax
mov    %rax,0x10(%rbx)
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%edx
lea    0xeac(%rip),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%edx
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%edx
mov    %rbp,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%edx
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%edx
mov    %rbp,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    129f <main+0x15f>
lea    0xd83(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Fatal error: memory allocation for a failed vlen = %d\0A\00"
@.str.1 = [14 x i8] c"Diagnostics:\0A\00"
@.str.2 = [15 x i8] c"nthreads = %d\0A\00"
@.str.3 = [15 x i8] c"indx = %d\0A\00"
@.str.4 = [15 x i8] c"n = %d\0A\00"
@.str.5 = [15 x i8] c"vlen = %d\0A\00"
@.str.6 = [36 x i8] c"Length of segment per thread is %d\0A\00"
@.str.7 = [27 x i8] c"Offset for vector a is %d\0A\00"
@.str.8 = [28 x i8] c"After the parallel region:\0A\00"
@.str.9 = [12 x i8] c"a[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %3
store i32 4, i32* %7
%11 = load i32, i32* %7
store i32 %11, i32* %6
store i32 1, i32* %4
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = mul nsw i32 %13, %14
%16 = add nsw i32 %12, %15
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %2
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %0
store i32 1, i32* %10
br label %26
25: ; preds = %0
store i32 0, i32* %10
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 -1, i32* %1
br label %105
32: ; preds = %26
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %32
store i32 0, i32* %8
br label %43
43: ; preds = %55, %42
%44 = load i32, i32* %8
%45 = load i32, i32* %5
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = load i32, i32* %8
%49 = sub nsw i32 0, %48
%50 = sub nsw i32 %49, 1
%51 = load i32*, i32** %2
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
br label %55
55: ; preds = %47
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %43
58: ; preds = %43
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %61)
store i32 0, i32* %9
%63 = load i32, i32* %7
%64 = load i32, i32* %3
%65 = load i32, i32* %9
%66 = mul nsw i32 %64, %65
%67 = add nsw i32 %63, %66
store i32 %67, i32* %6
%68 = load i32, i32* %6
store i32 %68, i32* %8
br label %69
69: ; preds = %82, %58
%70 = load i32, i32* %8
%71 = load i32, i32* %6
%72 = load i32, i32* %3
%73 = add nsw i32 %71, %72
%74 = icmp slt i32 %70, %73
br i1 %74, label %75, label %85
75: ; preds = %69
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
%78 = load i32*, i32** %2
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
store i32 %77, i32* %81
br label %82
82: ; preds = %75
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
store i32 %84, i32* %8
br label %69
85: ; preds = %69
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %8
br label %87
87: ; preds = %99, %85
%88 = load i32, i32* %8
%89 = load i32, i32* %5
%90 = icmp slt i32 %88, %89
br i1 %90, label %91, label %102
91: ; preds = %87
%92 = load i32, i32* %8
%93 = load i32*, i32** %2
%94 = load i32, i32* %8
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %92, i32 %97)
br label %99
99: ; preds = %91
%100 = load i32, i32* %8
%101 = add nsw i32 %100, 1
store i32 %101, i32* %8
br label %87
102: ; preds = %87
%103 = load i32*, i32** %2
%104 = call i32 @free(i32* %103)
store i32 0, i32* %1
br label %105
105: ; preds = %102, %29
%106 = load i32, i32* %1
ret i32 %106
}

LLVM IR (-O2):
@.str = [55 x i8] c"Fatal error: memory allocation for a failed vlen = %d\0A\00"
@.str.2 = [15 x i8] c"nthreads = %d\0A\00"
@.str.3 = [15 x i8] c"indx = %d\0A\00"
@.str.4 = [15 x i8] c"n = %d\0A\00"
@.str.5 = [15 x i8] c"vlen = %d\0A\00"
@.str.6 = [36 x i8] c"Length of segment per thread is %d\0A\00"
@.str.7 = [27 x i8] c"Offset for vector a is %d\0A\00"
@.str.9 = [12 x i8] c"a[%d] = %d\0A\00"
@str = [13 x i8] c"Diagnostics:\00"
@str.10 = [27 x i8] c"After the parallel region:\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 24)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 6)
br label %34
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 1)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 4)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 2)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 6)
%12 = getelementptr inbounds i32, i32* %2, i64 1
%13 = getelementptr inbounds i32, i32* %2, i64 2
%14 = getelementptr inbounds i32, i32* %2, i64 3
%15 = inttoptr i64 %1 to <4 x i32>*
store <4 x i32> <i32 -1, i32 -2, i32 -3, i32 -4>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %2, i64 4
store i32 -5, i32* %16
%17 = getelementptr inbounds i32, i32* %2, i64 5
store i32 -6, i32* %17
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 2)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 4)
store i32 1, i32* %16
store i32 1, i32* %17
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 0, i32 %21)
%23 = load i32, i32* %12
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 1, i32 %23)
%25 = load i32, i32* %13
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 2, i32 %25)
%27 = load i32, i32* %14
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 3, i32 %27)
%29 = load i32, i32* %16
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 %29)
%31 = load i32, i32* %17
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 5, i32 %31)
%33 = tail call i32 @free(i32* %2)
br label %34
34: ; preds = %6, %4
%35 = phi i32 [ -1, %4 ], [ 0, %6 ]
ret i32 %35
}