int test_unsignedlong() {
  int i;
  unsigned long reds[3] = {(4096 * (4096 - 1) / 2), (4096 * (4096 - 1) / 2)};
#pragma acc parallel loop
  for (i = 0; i < 4096; i++) {
    unsigned long v;
    v = (unsigned long)i;
#pragma acc atomic
    reds[0] -= v;
#pragma acc atomic
    reds[1] = reds[1] - v;
  }
  for (i = 0; i < 2; i++) {
    if (reds[i] != 0) {
      return i + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_unsignedlong>:
push   %rbp
mov    %rsp,%rbp
mov    0xef5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xef2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeef(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1000,-0x8(%rbp)
jge    116a <test_unsignedlong+0x6a>
movslq -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112c <test_unsignedlong+0x2c>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ac <test_unsignedlong+0xac>
movslq -0x8(%rbp),%rax
cmpq   $0x0,-0x20(%rbp,%rax,8)
je     1199 <test_unsignedlong+0x99>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <test_unsignedlong+0xb3>
jmp    119e <test_unsignedlong+0x9e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1171 <test_unsignedlong+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_unsignedlong>:
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i32 @test_unsignedlong() {
ret i32 0
}