#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*/ printf(char *, unsigned int, int, int, unsigned int,
                          unsigned int);
unsigned int setbits(unsigned int, int, int, unsigned int);
int main(void) {
  unsigned i;
  unsigned j;
  unsigned k;
  int p;
  int n;
  for (i = 0; i < 30000; i += 511) {
    for (j = 0; j < 1000; j += 37) {
      for (p = 0; p < 16; p++) {
        for (n = 1; n <= p + 1; n++) {
          k = setbits(i, p, n, j);
          printf("setbits(%u, %d, %d, %u) = %u\n", i, p, n, j, k);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7530,-0x8(%rbp)
jae    11fa <main+0xda>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jae    11e5 <main+0xc5>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11d2 <main+0xb2>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     11bf <main+0x9f>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1040 <setbits@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116f <main+0x4f>
jmp    11c4 <main+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <main+0x3e>
jmp    11d7 <main+0xb7>
mov    -0xc(%rbp),%eax
add    $0x25,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <main+0x2a>
jmp    11ea <main+0xca>
mov    -0x8(%rbp),%eax
add    $0x1ff,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
lea    0xecb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %r13d,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
call   1040 <setbits@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r12d,%r8d
mov    %eax,%r9d
call   1030 <printf@plt>
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x2,%eax
jne    1170 <main+0x50>
add    $0x1,%ebp
add    $0xffffffff,%r13d
cmp    $0x10,%ebp
jne    1160 <main+0x40>
lea    0x25(%r12),%eax
cmp    $0x3c3,%r12d
mov    %eax,%r12d
jb     1150 <main+0x30>
lea    0x1ff(%r15),%eax
cmp    $0x7331,%r15d
mov    %eax,%r15d
jb     1140 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"setbits(%u, %d, %d, %u) = %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %48, %0
%8 = load i32, i32* %2
%9 = icmp ult i32 %8, 30000
br i1 %9, label %10, label %51
10: ; preds = %7
store i32 0, i32* %3
br label %11
11: ; preds = %44, %10
%12 = load i32, i32* %3
%13 = icmp ult i32 %12, 1000
br i1 %13, label %14, label %47
14: ; preds = %11
store i32 0, i32* %5
br label %15
15: ; preds = %40, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 16
br i1 %17, label %18, label %43
18: ; preds = %15
store i32 1, i32* %6
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
%23 = icmp sle i32 %20, %22
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = load i32, i32* %2
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = load i32, i32* %3
%29 = call i32 @setbits(i32 %25, i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %4
%30 = load i32, i32* %2
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %32, i32 %33, i32 %34)
br label %36
36: ; preds = %24
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %19
39: ; preds = %19
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %15
43: ; preds = %15
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = add i32 %45, 37
store i32 %46, i32* %3
br label %11
47: ; preds = %11
br label %48
48: ; preds = %47
%49 = load i32, i32* %2
%50 = add i32 %49, 511
store i32 %50, i32* %2
br label %7
51: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"setbits(%u, %d, %d, %u) = %u\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %21
%2 = phi i32 [ 0, %0 ], [ %22, %21 ]
br label %3
3: ; preds = %1, %18
%4 = phi i32 [ 0, %1 ], [ %19, %18 ]
br label %9
5: ; preds = %12
%6 = add nuw nsw i32 %11, 1
%7 = add nuw nsw i32 %10, 1
%8 = icmp eq i32 %6, 16
br i1 %8, label %18, label %9
9: ; preds = %3, %5
%10 = phi i32 [ 2, %3 ], [ %7, %5 ]
%11 = phi i32 [ 0, %3 ], [ %6, %5 ]
br label %12
12: ; preds = %9, %12
%13 = phi i32 [ 1, %9 ], [ %16, %12 ]
%14 = tail call i32 @setbits(i32 %2, i32 %11, i32 %13, i32 %4)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %11, i32 %13, i32 %4, i32 %14)
%16 = add nuw nsw i32 %13, 1
%17 = icmp eq i32 %16, %10
br i1 %17, label %5, label %12
18: ; preds = %5
%19 = add nuw nsw i32 %4, 37
%20 = icmp ult i32 %4, 963
br i1 %20, label %3, label %21
21: ; preds = %18
%22 = add nuw nsw i32 %2, 511
%23 = icmp ult i32 %2, 29489
br i1 %23, label %1, label %24
24: ; preds = %21
ret i32 0
}