void countForever(int p) {
  int j, k, l;
  unsigned long count = 0;
  j = getpid();
  p = p % 3;
  k = setpriority(j, p);
  if (k != 0)
    printf(1, "setpriority didn't work 1. ret:%d, j:%d, p:%d.\n", k, j, p);
  printf(1, "%d: start prio %d\n", j, p);
  l = -1;
  if (!setpriority(l, p))
    printf(1, "setpriority returned success on a bad argument! BAD!\n");
  else
    printf(1, "setpriority correctly rejected a bad arg. GOOD!\n");
  if (!setpriority(j, l))
    printf(1, "setpriority returned success on a bad argument! BAD!\n");
  else
    printf(1, "setpriority correctly rejected a bad arg. GOOD!\n");
  while (1) {
    count++;
    if ((count & 0xFFFFFFF) == 0) {
      p = (p + 1) % 3;
      k = setpriority(j, p);
      if (k != -0)
        printf(1, "setpriority didn't work 2. ret:%d, j:%d, p:%d.\n", k, j, p);
      printf(1, "%d: new prio %d\n", j, p);
    }
  }
}


x86 assembly (clang, -O0):
<countForever>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1050 <setpriority@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1192 <countForever+0x62>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%r8d
mov    $0x1,%edi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    $0x1,%edi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1050 <setpriority@plt>
cmp    $0x0,%eax
jne    11e0 <countForever+0xb0>
mov    $0x1,%edi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f3 <countForever+0xc3>
mov    $0x1,%edi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x0,%al
call   1050 <setpriority@plt>
cmp    $0x0,%eax
jne    1221 <countForever+0xf1>
mov    $0x1,%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1234 <countForever+0x104>
mov    $0x1,%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1239 <countForever+0x109>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0xfffffff,%rax
cmp    $0x0,%rax
jne    12ba <countForever+0x18a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1050 <setpriority@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     12a1 <countForever+0x171>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%r8d
mov    $0x1,%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    $0x1,%edi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1239 <countForever+0x109>

x86 assembly (clang, -O2):
<countForever>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r12d
movslq %ebx,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <setpriority@plt>
test   %eax,%eax
je     118b <countForever+0x5b>
lea    0xe89(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
mov    %r12d,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9e(%rip),%rsi
mov    $0x1,%edi
mov    %r12d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <setpriority@plt>
test   %eax,%eax
lea    0xe89(%rip),%rbp
lea    0xeb8(%rip),%r14
mov    %r14,%rsi
cmove  %rbp,%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1050 <setpriority@plt>
test   %eax,%eax
cmove  %rbp,%r14
mov    $0x1,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%r14
lea    0xea4(%rip),%r15
xor    %ebp,%ebp
jmp    1224 <countForever+0xf4>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ecx
neg    %ecx
and    $0x7,%ecx
je     1260 <countForever+0x130>
xor    %edx,%edx
mov    %rbp,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rax
add    $0x1,%edx
mov    %edx,%esi
and    $0xfffffff,%esi
mov    %ecx,%edi
and    $0xfffffff,%edi
cmp    %edi,%esi
jne    1240 <countForever+0x110>
jmp    1263 <countForever+0x133>
nopl   (%rax)
mov    %rbp,%rax
and    $0xfffffff,%ebp
cmp    $0xffffff8,%ebp
mov    %rax,%rbp
ja     128c <countForever+0x15c>
mov    %rax,%rbp
nopw   0x0(%rax,%rax,1)
add    $0x8,%rbp
test   $0xfffffff,%ebp
jne    1280 <countForever+0x150>
add    $0x1,%ebx
movslq %ebx,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <setpriority@plt>
test   %eax,%eax
je     1210 <countForever+0xe0>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r12d,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1210 <countForever+0xe0>

LLVM IR (-O0):
@.str = [48 x i8] c"setpriority didn't work 1. ret:%d, j:%d, p:%d.\0A\00"
@.str.1 = [19 x i8] c"%d: start prio %d\0A\00"
@.str.2 = [54 x i8] c"setpriority returned success on a bad argument! BAD!\0A\00"
@.str.3 = [49 x i8] c"setpriority correctly rejected a bad arg. GOOD!\0A\00"
@.str.4 = [48 x i8] c"setpriority didn't work 2. ret:%d, j:%d, p:%d.\0A\00"
@.str.5 = [17 x i8] c"%d: new prio %d\0A\00"
define void @countForever(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %2
store i64 0, i64* %6
%7 = call i32 (...) @getpid()
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = srem i32 %8, 3
store i32 %9, i32* %2
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %10, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
br label %20
20: ; preds = %15, %1
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
store i32 -1, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* %2
%26 = call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %24, i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %32
30: ; preds = %20
%31 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %33, i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41, %66
%43 = load i64, i64* %6
%44 = add i64 %43, 1
store i64 %44, i64* %6
%45 = load i64, i64* %6
%46 = and i64 %45, 268435455
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %66
48: ; preds = %42
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
%51 = srem i32 %50, 3
store i32 %51, i32* %2
%52 = load i32, i32* %3
%53 = load i32, i32* %2
%54 = call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %52, i32 %53)
store i32 %54, i32* %4
%55 = load i32, i32* %4
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %48
%58 = load i32, i32* %4
%59 = load i32, i32* %3
%60 = load i32, i32* %2
%61 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %59, i32 %60)
br label %62
62: ; preds = %57, %48
%63 = load i32, i32* %3
%64 = load i32, i32* %2
%65 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %63, i32 %64)
br label %66
66: ; preds = %62, %42
br label %42
}

LLVM IR (-O2):
@.str = [48 x i8] c"setpriority didn't work 1. ret:%d, j:%d, p:%d.\0A\00"
@.str.1 = [19 x i8] c"%d: start prio %d\0A\00"
@.str.2 = [54 x i8] c"setpriority returned success on a bad argument! BAD!\0A\00"
@.str.3 = [49 x i8] c"setpriority correctly rejected a bad arg. GOOD!\0A\00"
@.str.4 = [48 x i8] c"setpriority didn't work 2. ret:%d, j:%d, p:%d.\0A\00"
@.str.5 = [17 x i8] c"%d: new prio %d\0A\00"
define void @countForever(i32 %0) {
%2 = tail call i32 (...) @getpid()
%3 = srem i32 %0, 3
%4 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %2, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %2, i32 %3)
br label %8
8: ; preds = %6, %1
%9 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %3)
%10 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 -1, i32 %3)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0)
%13 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* %12)
%14 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %2, i32 -1)
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* %16)
br label %18
18: ; preds = %48, %8
%19 = phi i32 [ %43, %48 ], [ %3, %8 ]
%20 = phi i64 [ %41, %48 ], [ 0, %8 ]
%21 = trunc i64 %20 to i28
%22 = sub i28 0, %21
%23 = and i28 %22, 7
%24 = icmp eq i28 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %18, %25
%26 = phi i64 [ %28, %25 ], [ %20, %18 ]
%27 = phi i28 [ %29, %25 ], [ 0, %18 ]
%28 = add i64 %26, 1
%29 = add i28 %27, 1
%30 = icmp eq i28 %29, %23
br i1 %30, label %31, label %25
31: ; preds = %25, %18
%32 = phi i64 [ undef, %18 ], [ %28, %25 ]
%33 = phi i64 [ %20, %18 ], [ %28, %25 ]
%34 = icmp ugt i28 %21, -8
br i1 %34, label %40, label %35
35: ; preds = %31, %35
%36 = phi i64 [ %37, %35 ], [ %33, %31 ]
%37 = add i64 %36, 8
%38 = and i64 %37, 268435455
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %35
40: ; preds = %35, %31
%41 = phi i64 [ %32, %31 ], [ %37, %35 ]
%42 = add nsw i32 %19, 1
%43 = srem i32 %42, 3
%44 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @setpriority to i32 (i32, i32, ...)*)(i32 %2, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %40
%47 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %2, i32 %43)
br label %48
48: ; preds = %46, %40
%49 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %2, i32 %43)
br label %18
}