#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int work(int, int, int, int *);
int main(int argc, char *argv[]) {
  int *aptr;
  int i;
  int result1, result2, result3, result4;
  aptr = (int *)malloc(1000 * sizeof(int));
  for (i = 0; i < 1000; i++)
    *(aptr + i) = i;
  result1 = work(0, 500, 0, aptr);
  result2 = work(0, 500, 1, aptr);
  result3 = work(500, 1000, 0, aptr);
  result4 = work(500, 1000, 1, aptr);
  if ((result1 + result3) == (result2 + result4 - 1000))
    printf("Correct Result!\n");
  else
    printf("Wrong Result!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    1184 <main+0x54>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <main+0x2b>
mov    -0x18(%rbp),%rcx
xor    %edx,%edx
mov    $0x1f4,%esi
mov    %edx,%edi
call   1030 <work@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
xor    %edi,%edi
mov    $0x1f4,%esi
mov    $0x1,%edx
call   1030 <work@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rcx
mov    $0x1f4,%edi
mov    $0x3e8,%esi
xor    %edx,%edx
call   1030 <work@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
mov    $0x1f4,%edi
mov    $0x3e8,%esi
mov    $0x1,%edx
call   1030 <work@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    -0x2c(%rbp),%ecx
sub    $0x3e8,%ecx
cmp    %ecx,%eax
jne    120f <main+0xdf>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
jmp    121b <main+0xeb>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movdqa 0xeb4(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xeb6(%rip),%xmm8
movdqa 0xebd(%rip),%xmm9
movdqa 0xec4(%rip),%xmm10
movdqa 0xecb(%rip),%xmm11
movdqa 0xed2(%rip),%xmm12
movdqa 0xeda(%rip),%xmm6
movdqa 0xee2(%rip),%xmm7
movdqa 0xeea(%rip),%xmm1
movdqa 0xef2(%rip),%xmm2
movdqa 0xefa(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%rbx,%rax,4)
ff ff
movdqu %xmm4,-0x80(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%rbx,%rax,4)
movdqu %xmm5,-0x60(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%rbx,%rax,4)
movdqu %xmm5,-0x40(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%rbx,%rax,4)
movdqu %xmm5,-0x20(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%rbx,%rax,4)
movdqu %xmm5,(%rbx,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x40c,%rax
jne    11b0 <main+0x80>
xor    %edi,%edi
mov    $0x1f4,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1040 <work@plt>
mov    %eax,%r14d
xor    %edi,%edi
mov    $0x1f4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <work@plt>
mov    %eax,%r15d
mov    $0x1f4,%edi
mov    $0x3e8,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1040 <work@plt>
mov    %eax,%ebp
mov    $0x1f4,%edi
mov    $0x3e8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <work@plt>
add    %r14d,%ebp
add    %r15d,%eax
add    $0xfffffc18,%eax
cmp    %eax,%ebp
lea    0xe03(%rip),%rax
lea    0xdee(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Correct Result!\0A\00"
@.str.1 = [15 x i8] c"Wrong Result!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 @malloc(i32 4000)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %6
store i32 0, i32* %7
br label %14
14: ; preds = %23, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 1000
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %7
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 %18, i32* %22
br label %23
23: ; preds = %17
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %14
26: ; preds = %14
%27 = load i32*, i32** %6
%28 = call i32 @work(i32 0, i32 500, i32 0, i32* %27)
store i32 %28, i32* %8
%29 = load i32*, i32** %6
%30 = call i32 @work(i32 0, i32 500, i32 1, i32* %29)
store i32 %30, i32* %9
%31 = load i32*, i32** %6
%32 = call i32 @work(i32 500, i32 1000, i32 0, i32* %31)
store i32 %32, i32* %10
%33 = load i32*, i32** %6
%34 = call i32 @work(i32 500, i32 1000, i32 1, i32* %33)
store i32 %34, i32* %11
%35 = load i32, i32* %8
%36 = load i32, i32* %10
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %9
%39 = load i32, i32* %11
%40 = add nsw i32 %38, %39
%41 = sub nsw i32 %40, 1000
%42 = icmp eq i32 %37, %41
br i1 %42, label %43, label %45
43: ; preds = %26
%44 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %47
45: ; preds = %26
%46 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
ret i32 0
}

LLVM IR (-O2):
@str = [14 x i8] c"Wrong Result!\00"
@str.2 = [16 x i8] c"Correct Result!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 4000)
%4 = inttoptr i64 %3 to i32*
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %41, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %2 ], [ %42, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = getelementptr inbounds i32, i32* %4, i64 %6
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %12
%13 = add nuw nsw i64 %6, 8
%14 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%15 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%16 = getelementptr inbounds i32, i32* %4, i64 %13
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %19
%20 = add nuw nsw i64 %6, 16
%21 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%22 = add <4 x i32> %7, <i32 20, i32 20, i32 20, i32 20>
%23 = getelementptr inbounds i32, i32* %4, i64 %20
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %26
%27 = add nuw nsw i64 %6, 24
%28 = add <4 x i32> %7, <i32 24, i32 24, i32 24, i32 24>
%29 = add <4 x i32> %7, <i32 28, i32 28, i32 28, i32 28>
%30 = getelementptr inbounds i32, i32* %4, i64 %27
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %31
%32 = getelementptr inbounds i32, i32* %30, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %33
%34 = add nuw nsw i64 %6, 32
%35 = add <4 x i32> %7, <i32 32, i32 32, i32 32, i32 32>
%36 = add <4 x i32> %7, <i32 36, i32 36, i32 36, i32 36>
%37 = getelementptr inbounds i32, i32* %4, i64 %34
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %38
%39 = getelementptr inbounds i32, i32* %37, i64 4
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %40
%41 = add nuw nsw i64 %6, 40
%42 = add <4 x i32> %7, <i32 40, i32 40, i32 40, i32 40>
%43 = icmp eq i64 %41, 1000
br i1 %43, label %44, label %5
44: ; preds = %5
%45 = tail call i32 @work(i32 0, i32 500, i32 0, i32* %4)
%46 = tail call i32 @work(i32 0, i32 500, i32 1, i32* %4)
%47 = tail call i32 @work(i32 500, i32 1000, i32 0, i32* %4)
%48 = tail call i32 @work(i32 500, i32 1000, i32 1, i32* %4)
%49 = add nsw i32 %47, %45
%50 = add i32 %46, -1000
%51 = add i32 %50, %48
%52 = icmp eq i32 %49, %51
%53 = select i1 %52, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0)
%54 = tail call i32 @puts(i8* dereferenceable(1) %53)
ret i32 0
}