#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_FAILURE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
long long atoll(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(long long);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
long long sum(int *, long long);
int main(int argc, char **argv) {
  char *awnser[] = {"bad", "ok"};
  long long int i, vsum, n;
  int *v;
  double elapsed, start, end;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <number of elements>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  n = atoll(argv[1]);
  printf("number of elements: %lld\n", n);
  v = (int *)malloc(n * sizeof(int));
  assert(v != NULL);
  for (i = 0; i < n; i++)
    v[i] = 1;
  start = omp_get_wtime();
  vsum = sum(v, n);
  end = omp_get_wtime();
  elapsed = end - start;
  printf("sum value is %s\ntime: %.3f seconds\n", awnser[vsum == n], elapsed);
  free(v);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c53(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c50(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f0 <main+0x60>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2a(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoll@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
shl    $0x2,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    126c <main+0xdc>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    123e <main+0xae>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <sum@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x20(%rbp,%rax,8),%rsi
movsd  -0x48(%rbp),%xmm0
lea    0xd7a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    12e6 <main+0x156>
mov    0x8(%rsi),%rdi
call   1060 <atoll@plt>
mov    %rax,%r14
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x0(,%r14,4),%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
test   %r14,%r14
jle    131c <main+0x18c>
cmp    $0x8,%r14
jae    11f3 <main+0x63>
xor    %eax,%eax
jmp    130c <main+0x17c>
mov    %r14,%rax
and    $0xfffffffffffffff8,%rax
lea    -0x8(%rax),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x7,%ecx
cmp    $0x38,%rsi
jae    121b <main+0x8b>
xor    %esi,%esi
jmp    12b5 <main+0x125>
and    $0xfffffffffffffff8,%rdx
xor    %esi,%esi
movapd 0xdd7(%rip),%xmm0
nopl   0x0(%rax)
movupd %xmm0,(%rbx,%rsi,4)
movupd %xmm0,0x10(%rbx,%rsi,4)
movupd %xmm0,0x20(%rbx,%rsi,4)
movupd %xmm0,0x30(%rbx,%rsi,4)
movupd %xmm0,0x40(%rbx,%rsi,4)
movupd %xmm0,0x50(%rbx,%rsi,4)
movupd %xmm0,0x60(%rbx,%rsi,4)
movupd %xmm0,0x70(%rbx,%rsi,4)
movupd %xmm0,0x80(%rbx,%rsi,4)
movupd %xmm0,0x90(%rbx,%rsi,4)
movupd %xmm0,0xa0(%rbx,%rsi,4)
movupd %xmm0,0xb0(%rbx,%rsi,4)
movupd %xmm0,0xc0(%rbx,%rsi,4)
movupd %xmm0,0xd0(%rbx,%rsi,4)
movupd %xmm0,0xe0(%rbx,%rsi,4)
movupd %xmm0,0xf0(%rbx,%rsi,4)
add    $0x40,%rsi
add    $0xfffffffffffffff8,%rdx
jne    1230 <main+0xa0>
test   %rcx,%rcx
je     1317 <main+0x187>
lea    (%rbx,%rsi,4),%rdx
add    $0x10,%rdx
shl    $0x5,%rcx
xor    %esi,%esi
movapd 0xd30(%rip),%xmm0
movupd %xmm0,-0x10(%rdx,%rsi,1)
movupd %xmm0,(%rdx,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%rcx
jne    12d0 <main+0x140>
jmp    1317 <main+0x187>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd1e(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movl   $0x1,(%rbx,%rax,4)
add    $0x1,%rax
cmp    %rax,%r14
jne    130c <main+0x17c>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sum@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
xor    %eax,%eax
cmp    %r14,%r15
sete   %al
lea    0xd25(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0xcf0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"bad\00"
@.str.1 = [3 x i8] c"ok\00"
@__const.main.awnser = [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0)]
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s <number of elements>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [26 x i8] c"number of elements: %lld\0A\00"
@.str.4 = [36 x i8] c"sum value is %s\0Atime: %.3f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8*]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [2 x i8*]* %6 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @atoll(i8* %28)
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %30)
%32 = load i64, i64* %9
%33 = mul i64 %32, 4
%34 = call i64 @malloc(i64 %33)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %10
%36 = load i32*, i32** %10
%37 = icmp ne i32* %36, null
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
store i64 0, i64* %7
br label %40
40: ; preds = %48, %25
%41 = load i64, i64* %7
%42 = load i64, i64* %9
%43 = icmp slt i64 %41, %42
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i32*, i32** %10
%46 = load i64, i64* %7
%47 = getelementptr inbounds i32, i32* %45, i64 %46
store i32 1, i32* %47
br label %48
48: ; preds = %44
%49 = load i64, i64* %7
%50 = add nsw i64 %49, 1
store i64 %50, i64* %7
br label %40
51: ; preds = %40
%52 = call double (...) @omp_get_wtime()
store double %52, double* %12
%53 = load i32*, i32** %10
%54 = load i64, i64* %9
%55 = call i64 @sum(i32* %53, i64 %54)
store i64 %55, i64* %8
%56 = call double (...) @omp_get_wtime()
store double %56, double* %13
%57 = load double, double* %13
%58 = load double, double* %12
%59 = fsub double %57, %58
store double %59, double* %11
%60 = load i64, i64* %8
%61 = load i64, i64* %9
%62 = icmp eq i64 %60, %61
%63 = zext i1 %62 to i32
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %64
%66 = load i8*, i8** %65
%67 = load double, double* %11
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %66, double %67)
%69 = load i32*, i32** %10
%70 = call i32 @free(i32* %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"bad\00"
@.str.1 = [3 x i8] c"ok\00"
@reltable.main = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32)]
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s <number of elements>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [26 x i8] c"number of elements: %lld\0A\00"
@.str.4 = [36 x i8] c"sum value is %s\0Atime: %.3f seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @atoll(i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %13)
%15 = shl i64 %13, 2
%16 = tail call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i32*
%18 = icmp ne i64 %16, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = icmp sgt i64 %13, 0
br i1 %21, label %22, label %100
22: ; preds = %10
%23 = icmp ult i64 %13, 8
br i1 %23, label %93, label %24
24: ; preds = %22
%25 = and i64 %13, -8
%26 = add i64 %25, -8
%27 = lshr exact i64 %26, 3
%28 = add nuw nsw i64 %27, 1
%29 = and i64 %28, 7
%30 = icmp ult i64 %26, 56
br i1 %30, label %78, label %31
31: ; preds = %24
%32 = and i64 %28, 4611686018427387896
br label %33
33: ; preds = %33, %31
%34 = phi i64 [ 0, %31 ], [ %75, %33 ]
%35 = phi i64 [ 0, %31 ], [ %76, %33 ]
%36 = getelementptr inbounds i32, i32* %17, i64 %34
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %37
%38 = getelementptr inbounds i32, i32* %36, i64 4
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %39
%40 = or i64 %34, 8
%41 = getelementptr inbounds i32, i32* %17, i64 %40
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %42
%43 = getelementptr inbounds i32, i32* %41, i64 4
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %44
%45 = or i64 %34, 16
%46 = getelementptr inbounds i32, i32* %17, i64 %45
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %47
%48 = getelementptr inbounds i32, i32* %46, i64 4
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %49
%50 = or i64 %34, 24
%51 = getelementptr inbounds i32, i32* %17, i64 %50
%52 = bitcast i32* %51 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %52
%53 = getelementptr inbounds i32, i32* %51, i64 4
%54 = bitcast i32* %53 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %54
%55 = or i64 %34, 32
%56 = getelementptr inbounds i32, i32* %17, i64 %55
%57 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %57
%58 = getelementptr inbounds i32, i32* %56, i64 4
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %59
%60 = or i64 %34, 40
%61 = getelementptr inbounds i32, i32* %17, i64 %60
%62 = bitcast i32* %61 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %62
%63 = getelementptr inbounds i32, i32* %61, i64 4
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %64
%65 = or i64 %34, 48
%66 = getelementptr inbounds i32, i32* %17, i64 %65
%67 = bitcast i32* %66 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %67
%68 = getelementptr inbounds i32, i32* %66, i64 4
%69 = bitcast i32* %68 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %69
%70 = or i64 %34, 56
%71 = getelementptr inbounds i32, i32* %17, i64 %70
%72 = bitcast i32* %71 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %72
%73 = getelementptr inbounds i32, i32* %71, i64 4
%74 = bitcast i32* %73 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %74
%75 = add nuw i64 %34, 64
%76 = add nuw i64 %35, 8
%77 = icmp eq i64 %76, %32
br i1 %77, label %78, label %33
78: ; preds = %33, %24
%79 = phi i64 [ 0, %24 ], [ %75, %33 ]
%80 = icmp eq i64 %29, 0
br i1 %80, label %91, label %81
81: ; preds = %78, %81
%82 = phi i64 [ %88, %81 ], [ %79, %78 ]
%83 = phi i64 [ %89, %81 ], [ 0, %78 ]
%84 = getelementptr inbounds i32, i32* %17, i64 %82
%85 = bitcast i32* %84 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %85
%86 = getelementptr inbounds i32, i32* %84, i64 4
%87 = bitcast i32* %86 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %87
%88 = add nuw i64 %82, 8
%89 = add i64 %83, 1
%90 = icmp eq i64 %89, %29
br i1 %90, label %91, label %81
91: ; preds = %81, %78
%92 = icmp eq i64 %13, %25
br i1 %92, label %100, label %93
93: ; preds = %22, %91
%94 = phi i64 [ 0, %22 ], [ %25, %91 ]
br label %95
95: ; preds = %93, %95
%96 = phi i64 [ %98, %95 ], [ %94, %93 ]
%97 = getelementptr inbounds i32, i32* %17, i64 %96
store i32 1, i32* %97
%98 = add nuw nsw i64 %96, 1
%99 = icmp eq i64 %98, %13
br i1 %99, label %100, label %95
100: ; preds = %95, %91, %10
%101 = tail call double (...) @omp_get_wtime()
%102 = tail call i64 @sum(i32* %17, i64 %13)
%103 = tail call double (...) @omp_get_wtime()
%104 = fsub double %103, %101
%105 = icmp eq i64 %102, %13
%106 = zext i1 %105 to i64
%107 = shl i64 %106, 2
%108 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.main to i8*), i64 %107)
%109 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %108, double %104)
%110 = tail call i32 @free(i32* %17)
ret i32 0
}