#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 *, ...);
void gen_bit(int bitsize, int msb, const char *macro, int nr_bits) {
  int i;
  printf("\n/* Test the %s macro */\n", macro);
  printf("test_tuples %s_tuples[%d] = {\n", macro, nr_bits);
  for (i = 0; i < nr_bits; i++) {
    unsigned long long bit = 1;
    if (msb == 0)
      bit <<= nr_bits - i - 1;
    else
      bit <<= i;
    if (bitsize == 32)
      bit = (unsigned)bit;
    printf("  { __LINE__, ");
    printf("%d, %2d, ", -1, i);
    printf("%s (%2d), ", macro, i);
    printf("UNSIGNED64 (0x%08lx%08lx), ", (long)(bit >> 32), (long)bit);
    printf("},\n");
  }
  printf("};\n");
  printf("\n");
  printf("test_spec %s_test = { __FILE__, \"%s\", 1, %d, %s_tuples, };\n",
         macro, macro, nr_bits, macro);
  printf("\n");
}


x86 assembly (clang, -O0):
<gen_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121f <gen_bit+0x10f>
movq   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    118c <gen_bit+0x7c>
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
shl    %cl,%rax
mov    %rax,-0x20(%rbp)
jmp    119c <gen_bit+0x8c>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
shl    %cl,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x20,-0x4(%rbp)
jne    11b0 <gen_bit+0xa0>
mov    -0x20(%rbp),%rax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edx
lea    0xe80(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
shr    $0x20,%rsi
mov    -0x20(%rbp),%rdx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <gen_bit+0x43>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xeb3(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebc(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,(%rsp)
test   %r14d,%r14d
jle    1216 <gen_bit+0xe6>
mov    (%rsp),%rax
lea    -0x1(%rax),%r13d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r15d,%r15d
mov    %r14d,%ecx
cmove  %r13d,%ecx
mov    $0x1,%eax
shl    %cl,%rax
cmp    $0x20,%ebp
mov    %eax,%r12d
cmovne %rax,%r12
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0xffffffff,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rsi
shr    $0x20,%rsi
lea    0xe6b(%rip),%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r14d
add    $0xffffffff,%r13d
jb     1190 <gen_bit+0x60>
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    (%rsp),%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"\0A/* Test the %s macro */\0A\00"
@.str.1 = [31 x i8] c"test_tuples %s_tuples[%d] = {\0A\00"
@.str.2 = [15 x i8] c" { __LINE__, \00"
@.str.3 = [10 x i8] c"%d, %2d, \00"
@.str.4 = [11 x i8] c"%s (%2d), \00"
@.str.5 = [28 x i8] c"UNSIGNED64 (0x%08lx%08lx), \00"
@.str.6 = [4 x i8] c"},\0A\00"
@.str.7 = [4 x i8] c"};\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [60 x i8] c"test_spec %s_test = { __FILE__, \22%s\22, 1, %d, %s_tuples, };\0A\00"
define void @gen_bit(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14)
store i32 0, i32* %9
br label %16
16: ; preds = %55, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %58
20: ; preds = %16
store i64 1, i64* %10
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = sub nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = load i64, i64* %10
%29 = zext i32 %27 to i64
%30 = shl i64 %28, %29
store i64 %30, i64* %10
br label %36
31: ; preds = %20
%32 = load i32, i32* %9
%33 = load i64, i64* %10
%34 = zext i32 %32 to i64
%35 = shl i64 %33, %34
store i64 %35, i64* %10
br label %36
36: ; preds = %31, %23
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 32
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i64, i64* %10
%41 = trunc i64 %40 to i32
%42 = zext i32 %41 to i64
store i64 %42, i64* %10
br label %43
43: ; preds = %39, %36
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* %9
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32 %45)
%47 = load i8*, i8** %7
%48 = load i32, i32* %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %47, i32 %48)
%50 = load i64, i64* %10
%51 = lshr i64 %50, 32
%52 = load i64, i64* %10
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i64 %51, i64 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %43
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %16
58: ; preds = %16
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%61 = load i8*, i8** %7
%62 = load i8*, i8** %7
%63 = load i32, i32* %8
%64 = load i8*, i8** %7
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i8* %61, i8* %62, i32 %63, i8* %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"\0A/* Test the %s macro */\0A\00"
@.str.1 = [31 x i8] c"test_tuples %s_tuples[%d] = {\0A\00"
@.str.2 = [15 x i8] c" { __LINE__, \00"
@.str.3 = [10 x i8] c"%d, %2d, \00"
@.str.4 = [11 x i8] c"%s (%2d), \00"
@.str.5 = [28 x i8] c"UNSIGNED64 (0x%08lx%08lx), \00"
@.str.9 = [60 x i8] c"test_spec %s_test = { __FILE__, \22%s\22, 1, %d, %s_tuples, };\0A\00"
@str = [3 x i8] c"};\00"
@str.10 = [3 x i8] c"},\00"
define void @gen_bit(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %28
8: ; preds = %4
%9 = icmp eq i32 %1, 0
%10 = icmp eq i32 %0, 32
br label %11
11: ; preds = %8, %11
%12 = phi i32 [ 0, %8 ], [ %26, %11 ]
%13 = xor i32 %12, -1
%14 = add i32 %13, %3
%15 = select i1 %9, i32 %14, i32 %12
%16 = zext i32 %15 to i64
%17 = shl nuw i64 1, %16
%18 = and i64 %17, 4294967295
%19 = select i1 %10, i64 %18, i64 %17
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32 %12)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %12)
%23 = lshr i64 %19, 32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i64 %23, i64 %19)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.10, i64 0, i64 0))
%26 = add nuw nsw i32 %12, 1
%27 = icmp eq i32 %26, %3
br i1 %27, label %28, label %11
28: ; preds = %11, %4
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @putchar(i32 10)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i8* %2, i8* %2, i32 %3, i8* %2)
%32 = tail call i32 @putchar(i32 10)
ret void
}