#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 */
struct bitmask {
  int dummy;
};
typedef int /*<<< orphan*/ mask;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ bitmap_scnprintf(char *, int, struct bitmask *);
scalar_t__ memcmp(struct bitmask *, struct bitmask *, int);
struct bitmask *numa_bitmask_alloc(int);
int /*<<< orphan*/ numa_bitmask_clearall(struct bitmask *);
int /*<<< orphan*/ numa_bitmask_setbit(struct bitmask *, int);
scalar_t__ numa_parse_bitmap(char *, struct bitmask *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int main(void) {
  char buf[1024];
  struct bitmask *mask, *mask2;
  int i;
  mask = numa_bitmask_alloc(300);
  mask2 = numa_bitmask_alloc(300);
  printf("Testing bitmap functions\n");
  for (i = 0; i < 300; i++) {
    numa_bitmask_clearall(mask);
    numa_bitmask_clearall(mask2);
    numa_bitmask_setbit(mask, i);
    bitmap_scnprintf(buf, sizeof(buf), mask);
    strcat(buf, "\n");
    if (numa_parse_bitmap(buf, mask2) < 0)
      assert(0);
    if (memcmp(mask, mask2, sizeof(mask))) {
      bitmap_scnprintf(buf, sizeof(buf), mask2);
      printf("mask2 differs: %s\n", buf);
      assert(0);
    }
  }
  printf("Passed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x12c,%edi
call   10b0 <numa_bitmask_alloc@plt>
mov    %rax,-0x418(%rbp)
mov    $0x12c,%edi
call   10b0 <numa_bitmask_alloc@plt>
mov    %rax,-0x420(%rbp)
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0x12c,-0x424(%rbp)
jge    12d4 <main+0x144>
mov    -0x418(%rbp),%rdi
call   1090 <numa_bitmask_clearall@plt>
mov    -0x420(%rbp),%rdi
call   1090 <numa_bitmask_clearall@plt>
mov    -0x418(%rbp),%rdi
mov    -0x424(%rbp),%esi
call   1030 <numa_bitmask_setbit@plt>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1060 <bitmap_scnprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rsi
call   1040 <numa_parse_bitmap@plt>
cmp    $0x0,%rax
jge    1265 <main+0xd5>
xor    %edi,%edi
call   1080 <assert@plt>
mov    -0x418(%rbp),%rdi
mov    -0x420(%rbp),%rsi
mov    $0x8,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     12bb <main+0x12b>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1060 <bitmap_scnprintf@plt>
lea    -0x410(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <assert@plt>
jmp    12c0 <main+0x130>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11dc <main+0x4c>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    $0x12c,%edi
call   10c0 <numa_bitmask_alloc@plt>
mov    %rax,%rbx
mov    $0x12c,%edi
call   10c0 <numa_bitmask_alloc@plt>
mov    %rax,%r14
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r15
lea    0xe30(%rip),%r12
lea    0xe18(%rip),%r13
xor    %ebp,%ebp
jmp    11ff <main+0x5f>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x12c,%ebp
je     1289 <main+0xe9>
mov    %rbx,%rdi
call   10a0 <numa_bitmask_clearall@plt>
mov    %r14,%rdi
call   10a0 <numa_bitmask_clearall@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <numa_bitmask_setbit@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <bitmap_scnprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <numa_parse_bitmap@plt>
test   %rax,%rax
jns    124b <main+0xab>
xor    %edi,%edi
call   1090 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     11f0 <main+0x50>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <bitmap_scnprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <assert@plt>
jmp    11f0 <main+0x50>
lea    0xd9c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
@.str = [26 x i8] c"Testing bitmap functions\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"mask2 differs: %s\0A\00"
@.str.3 = [8 x i8] c"Passed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca %struct.bitmask*
%4 = alloca %struct.bitmask*
%5 = alloca i32
store i32 0, i32* %1
%6 = call %struct.bitmask* @numa_bitmask_alloc(i32 300)
store %struct.bitmask* %6, %struct.bitmask** %3
%7 = call %struct.bitmask* @numa_bitmask_alloc(i32 300)
store %struct.bitmask* %7, %struct.bitmask** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %44, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 300
br i1 %11, label %12, label %47
12: ; preds = %9
%13 = load %struct.bitmask*, %struct.bitmask** %3
%14 = call i32 @numa_bitmask_clearall(%struct.bitmask* %13)
%15 = load %struct.bitmask*, %struct.bitmask** %4
%16 = call i32 @numa_bitmask_clearall(%struct.bitmask* %15)
%17 = load %struct.bitmask*, %struct.bitmask** %3
%18 = load i32, i32* %5
%19 = call i32 @numa_bitmask_setbit(%struct.bitmask* %17, i32 %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%21 = load %struct.bitmask*, %struct.bitmask** %3
%22 = call i32 @bitmap_scnprintf(i8* %20, i32 1024, %struct.bitmask* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%26 = load %struct.bitmask*, %struct.bitmask** %4
%27 = call i64 @numa_parse_bitmap(i8* %25, %struct.bitmask* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %12
%30 = call i32 @assert(i32 0)
br label %31
31: ; preds = %29, %12
%32 = load %struct.bitmask*, %struct.bitmask** %3
%33 = load %struct.bitmask*, %struct.bitmask** %4
%34 = call i64 @memcmp(%struct.bitmask* %32, %struct.bitmask* %33, i32 8)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%38 = load %struct.bitmask*, %struct.bitmask** %4
%39 = call i32 @bitmap_scnprintf(i8* %37, i32 1024, %struct.bitmask* %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 @assert(i32 0)
br label %43
43: ; preds = %36, %31
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %9
47: ; preds = %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"mask2 differs: %s\0A\00"
@str = [25 x i8] c"Testing bitmap functions\00"
@str.4 = [7 x i8] c"Passed\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call %struct.bitmask* @numa_bitmask_alloc(i32 300)
%4 = tail call %struct.bitmask* @numa_bitmask_alloc(i32 300)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %0, %24
%7 = phi i32 [ 0, %0 ], [ %25, %24 ]
%8 = call i32 @numa_bitmask_clearall(%struct.bitmask* %3)
%9 = call i32 @numa_bitmask_clearall(%struct.bitmask* %4)
%10 = call i32 @numa_bitmask_setbit(%struct.bitmask* %3, i32 %7)
%11 = call i32 @bitmap_scnprintf(i8* %2, i32 1024, %struct.bitmask* %3)
%12 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @numa_parse_bitmap(i8* %2, %struct.bitmask* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = call i32 @assert(i32 0)
br label %17
17: ; preds = %15, %6
%18 = call i64 @memcmp(%struct.bitmask* %3, %struct.bitmask* %4, i32 8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = call i32 @bitmap_scnprintf(i8* %2, i32 1024, %struct.bitmask* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%23 = call i32 @assert(i32 0)
br label %24
24: ; preds = %17, %20
%25 = add nuw nsw i32 %7, 1
%26 = icmp eq i32 %25, 300
br i1 %26, label %27, label %6
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}