#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 */
typedef int uint64_t;
struct axmap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ axmap_free(struct axmap *);
scalar_t__ axmap_isset(struct axmap *, int);
struct axmap *axmap_new(unsigned int);
int axmap_set_nr(struct axmap *, int, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int test_multi(size_t size, unsigned int bit_off) {
  unsigned int map_size = size;
  struct axmap *map;
  uint64_t val = bit_off;
  int i, err;
  printf("Test multi %llu entries %u offset...", (unsigned long long)size,
         bit_off);
  fflush(stdout);
  map = axmap_new(map_size);
  while (val + 128 <= map_size) {
    err = 0;
    for (i = val; i < val + 128; i++) {
      if (axmap_isset(map, val + i)) {
        printf("bit already set\n");
        err = 1;
        break;
      }
    }
    if (err)
      break;
    err = axmap_set_nr(map, val, 128);
    if (err != 128) {
      printf("only set %u bits\n", err);
      break;
    }
    err = 0;
    for (i = 0; i < 128; i++) {
      if (!axmap_isset(map, val + i)) {
        printf("bit not set: %llu\n", (unsigned long long)val + i);
        err = 1;
        break;
      }
    }
    val += 128;
    if (err)
      break;
  }
  if (!err)
    printf("pass!\n");
  axmap_free(map);
  return err;
}


x86 assembly (clang, -O0):
<test_multi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%edi
call   1070 <axmap_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x80,%eax
cmp    -0x10(%rbp),%eax
ja     12f4 <test_multi+0x194>
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x80,%ecx
cmp    %ecx,%eax
jge    1223 <test_multi+0xc3>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
call   1040 <axmap_isset@plt>
cmp    $0x0,%rax
je     1210 <test_multi+0xb0>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x24(%rbp)
jmp    1223 <test_multi+0xc3>
jmp    1215 <test_multi+0xb5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <test_multi+0x69>
cmpl   $0x0,-0x24(%rbp)
je     1232 <test_multi+0xd2>
jmp    12f4 <test_multi+0x194>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x80,%edx
call   1080 <axmap_set_nr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x80,-0x24(%rbp)
je     1269 <test_multi+0x109>
mov    -0x24(%rbp),%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f4 <test_multi+0x194>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x80,-0x20(%rbp)
jge    12d5 <test_multi+0x175>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
call   1040 <axmap_isset@plt>
cmp    $0x0,%rax
jne    12c2 <test_multi+0x162>
movslq -0x1c(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x24(%rbp)
jmp    12d5 <test_multi+0x175>
jmp    12c7 <test_multi+0x167>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1277 <test_multi+0x117>
mov    -0x1c(%rbp),%eax
add    $0x80,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12ef <test_multi+0x18f>
jmp    12f4 <test_multi+0x194>
jmp    11ab <test_multi+0x4b>
cmpl   $0x0,-0x24(%rbp)
jne    130c <test_multi+0x1ac>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <axmap_free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_multi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    %ebx,%edi
call   1080 <axmap_new@plt>
mov    %rax,%r12
lea    0x80(%r14),%r13d
cmp    %ebx,%r13d
jbe    11cf <test_multi+0x5f>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1291 <test_multi+0x121>
lea    (%r14,%r14,1),%ebp
mov    %rbx,0x10(%rsp)
movslq %r14d,%rbx
mov    %ebp,0xc(%rsp)
mov    %r14d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <axmap_isset@plt>
test   %rax,%rax
jne    126d <test_multi+0xfd>
add    $0x1,%r15d
add    $0x1,%ebp
cmp    %r13d,%r15d
jl     11f0 <test_multi+0x80>
mov    %r12,%rdi
mov    %r14d,%esi
mov    $0x80,%edx
call   1090 <axmap_set_nr@plt>
cmp    $0x80,%eax
jne    12aa <test_multi+0x13a>
mov    $0x80,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <axmap_isset@plt>
test   %rax,%rax
je     127b <test_multi+0x10b>
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    1230 <test_multi+0xc0>
sub    $0xffffff80,%r13d
mov    0xc(%rsp),%ebp
add    $0x100,%ebp
sub    $0xffffff80,%r14d
mov    0x10(%rsp),%rbx
cmp    %ebx,%r13d
jbe    11d8 <test_multi+0x68>
jmp    11bc <test_multi+0x4c>
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
jmp    128c <test_multi+0x11c>
lea    0xdb5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %r12,%rdi
call   1060 <axmap_free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xd72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jne    1291 <test_multi+0x121>
jmp    11bc <test_multi+0x4c>

LLVM IR (-O0):
%struct.axmap = type { i32 }
@.str = [37 x i8] c"Test multi %llu entries %u offset...\00"
@stdout = global i32 0
@.str.1 = [17 x i8] c"bit already set\0A\00"
@.str.2 = [18 x i8] c"only set %u bits\0A\00"
@.str.3 = [19 x i8] c"bit not set: %llu\0A\00"
@.str.4 = [7 x i8] c"pass!\0A\00"
define i32 @test_multi(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.axmap*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%10 = load i64, i64* %3
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %4
store i32 %12, i32* %7
%13 = load i64, i64* %3
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %13, i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32, i32* %5
%19 = call %struct.axmap* @axmap_new(i32 %18)
store %struct.axmap* %19, %struct.axmap** %6
br label %20
20: ; preds = %86, %2
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 128
%23 = load i32, i32* %5
%24 = icmp ule i32 %22, %23
br i1 %24, label %25, label %87
25: ; preds = %20
store i32 0, i32* %9
%26 = load i32, i32* %7
store i32 %26, i32* %8
br label %27
27: ; preds = %42, %25
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 128
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load %struct.axmap*, %struct.axmap** %6
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = add nsw i32 %34, %35
%37 = call i64 @axmap_isset(%struct.axmap* %33, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %9
br label %45
41: ; preds = %32
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %27
45: ; preds = %39, %27
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
br label %87
49: ; preds = %45
%50 = load %struct.axmap*, %struct.axmap** %6
%51 = load i32, i32* %7
%52 = call i32 @axmap_set_nr(%struct.axmap* %50, i32 %51, i32 128)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp ne i32 %53, 128
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = load i32, i32* %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %87
58: ; preds = %49
store i32 0, i32* %9
store i32 0, i32* %8
br label %59
59: ; preds = %77, %58
%60 = load i32, i32* %8
%61 = icmp slt i32 %60, 128
br i1 %61, label %62, label %80
62: ; preds = %59
%63 = load %struct.axmap*, %struct.axmap** %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = add nsw i32 %64, %65
%67 = call i64 @axmap_isset(%struct.axmap* %63, i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %76, label %69
69: ; preds = %62
%70 = load i32, i32* %7
%71 = sext i32 %70 to i64
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = add i64 %71, %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %74)
store i32 1, i32* %9
br label %80
76: ; preds = %62
br label %77
77: ; preds = %76
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %59
80: ; preds = %69, %59
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 128
store i32 %82, i32* %7
%83 = load i32, i32* %9
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %80
br label %87
86: ; preds = %80
br label %20
87: ; preds = %85, %55, %48, %20
%88 = load i32, i32* %9
%89 = icmp ne i32 %88, 0
br i1 %89, label %92, label %90
90: ; preds = %87
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
%93 = load %struct.axmap*, %struct.axmap** %6
%94 = call i32 @axmap_free(%struct.axmap* %93)
%95 = load i32, i32* %9
ret i32 %95
}

LLVM IR (-O2):
%struct.axmap = type { i32 }
@.str = [37 x i8] c"Test multi %llu entries %u offset...\00"
@stdout = global i32 0
@.str.2 = [18 x i8] c"only set %u bits\0A\00"
@.str.3 = [19 x i8] c"bit not set: %llu\0A\00"
@str = [6 x i8] c"pass!\00"
@str.5 = [16 x i8] c"bit already set\00"
define i32 @test_multi(i64 %0, i32 %1) {
%3 = trunc i64 %0 to i32
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %0, i32 %1)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = tail call %struct.axmap* @axmap_new(i32 %3)
%8 = add nsw i32 %1, 128
%9 = icmp ugt i32 %8, %3
br i1 %9, label %45, label %13
10: ; preds = %39
%11 = add nsw i32 %14, 128
%12 = icmp ugt i32 %11, %3
br i1 %12, label %45, label %13
13: ; preds = %2, %10
%14 = phi i32 [ %11, %10 ], [ %8, %2 ]
%15 = phi i32 [ %14, %10 ], [ %1, %2 ]
br label %18
16: ; preds = %18
%17 = icmp slt i32 %23, %14
br i1 %17, label %18, label %26
18: ; preds = %13, %16
%19 = phi i32 [ %15, %13 ], [ %23, %16 ]
%20 = add nsw i32 %19, %15
%21 = tail call i64 @axmap_isset(%struct.axmap* %7, i32 %20)
%22 = icmp eq i64 %21, 0
%23 = add nsw i32 %19, 1
br i1 %22, label %16, label %24
24: ; preds = %18
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
br label %47
26: ; preds = %16
%27 = tail call i32 @axmap_set_nr(%struct.axmap* %7, i32 %15, i32 128)
%28 = icmp eq i32 %27, 128
br i1 %28, label %29, label %42
29: ; preds = %26, %39
%30 = phi i32 [ %40, %39 ], [ 0, %26 ]
%31 = add nsw i32 %30, %15
%32 = tail call i64 @axmap_isset(%struct.axmap* %7, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = sext i32 %15 to i64
%36 = zext i32 %30 to i64
%37 = add nsw i64 %36, %35
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %37)
br label %47
39: ; preds = %29
%40 = add nuw nsw i32 %30, 1
%41 = icmp eq i32 %40, 128
br i1 %41, label %10, label %29
42: ; preds = %26
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%44 = icmp eq i32 %27, 0
br i1 %44, label %45, label %47
45: ; preds = %10, %2, %42
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %34, %24, %45, %42
%48 = phi i32 [ 0, %45 ], [ %27, %42 ], [ 1, %24 ], [ 1, %34 ]
%49 = tail call i32 @axmap_free(%struct.axmap* %7)
ret i32 %48
}