#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*/ accumid_to_sigref_cal(int, int *, int *);
int /*<<< orphan*/ printf(char *, int, int, int, ...);
int sigref_cal_to_accumid(int, int);
void test_conversions() {
  int sigref[4] = {1, 1, 0, 0};
  int cal[4] = {0, 1, 0, 1};
  int accumid[4] = {1, 0, 3, 2};
  int i;
  int accum;
  int sr, cl;
  for (i = 0; i < 4; ++i) {
    accum = sigref_cal_to_accumid(sigref[i], cal[i]);
    if (accum != accumid[i]) {
      printf("sigref_cal_to_accumid error sr=%d cal=%d acc=%d, expected=%d\n",
             sigref[i], cal[i], accum, accumid[i]);
    }
    accumid_to_sigref_cal(accum, &sr, &cl);
    if (sr != sigref[i] || cl != cal[i]) {
      printf("accumid_to_sigref_cal error sr=%d cal=%d acc=%d\n", sr, cl,
             accum);
    }
  }
}


x86 assembly (clang, -O0):
<test_conversions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    123a <test_conversions+0x10a>
movslq -0x34(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%edi
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
call   1030 <sigref_cal_to_accumid@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
movslq -0x34(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     11de <test_conversions+0xae>
movslq -0x34(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%esi
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edx
mov    -0x38(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%r8d
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%edi
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <accumid_to_sigref_cal@plt>
mov    -0x3c(%rbp),%eax
movslq -0x34(%rbp),%rcx
cmp    -0x10(%rbp,%rcx,4),%eax
jne    1210 <test_conversions+0xe0>
mov    -0x40(%rbp),%eax
movslq -0x34(%rbp),%rcx
cmp    -0x20(%rbp,%rcx,4),%eax
je     1227 <test_conversions+0xf7>
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122c <test_conversions+0xfc>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1181 <test_conversions+0x51>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_conversions>:
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <sigref_cal_to_accumid@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
je     1165 <test_conversions+0x35>
lea    0xeb1(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %ebx,%ecx
mov    $0x1,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <accumid_to_sigref_cal@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
cmp    $0x1,%esi
jne    1187 <test_conversions+0x57>
test   %edx,%edx
je     1197 <test_conversions+0x67>
lea    0xeb0(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <sigref_cal_to_accumid@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11c9 <test_conversions+0x99>
lea    0xe4d(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %ebx,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <accumid_to_sigref_cal@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
cmp    $0x1,%esi
jne    11ec <test_conversions+0xbc>
cmp    $0x1,%edx
je     11fc <test_conversions+0xcc>
lea    0xe4b(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <sigref_cal_to_accumid@plt>
mov    %eax,%ebx
cmp    $0x3,%eax
je     1226 <test_conversions+0xf6>
lea    0xded(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %ebx,%ecx
mov    $0x3,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <accumid_to_sigref_cal@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %esi,%eax
or     %edx,%eax
je     1255 <test_conversions+0x125>
lea    0xdf2(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <sigref_cal_to_accumid@plt>
mov    %eax,%ebx
cmp    $0x2,%eax
je     1285 <test_conversions+0x155>
lea    0xd91(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    %ebx,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <accumid_to_sigref_cal@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
test   %esi,%esi
jne    12a7 <test_conversions+0x177>
cmp    $0x1,%edx
je     12b7 <test_conversions+0x187>
lea    0xd90(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_conversions.sigref = [4 x i32] [i32 1, i32 1, i32 0, i32 0]
@__const.test_conversions.cal = [4 x i32] [i32 0, i32 1, i32 0, i32 1]
@__const.test_conversions.accumid = [4 x i32] [i32 1, i32 0, i32 3, i32 2]
@.str = [62 x i8] c"sigref_cal_to_accumid error sr=%d cal=%d acc=%d, expected=%d\0A\00"
@.str.1 = [49 x i8] c"accumid_to_sigref_cal error sr=%d cal=%d acc=%d\0A\00"
define void @test_conversions() {
%1 = alloca [4 x i32]
%2 = alloca [4 x i32]
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [4 x i32]* %1 to i8*
%9 = bitcast [4 x i32]* %2 to i8*
%10 = bitcast [4 x i32]* %3 to i8*
store i32 0, i32* %4
br label %11
11: ; preds = %67, %0
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %70
14: ; preds = %11
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @sigref_cal_to_accumid(i32 %18, i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp ne i32 %24, %28
br i1 %29, label %30, label %45
30: ; preds = %14
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %38, i32 %39, i32 %43)
br label %45
45: ; preds = %30, %14
%46 = load i32, i32* %5
%47 = call i32 @accumid_to_sigref_cal(i32 %46, i32* %6, i32* %7)
%48 = load i32, i32* %6
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = icmp ne i32 %48, %52
br i1 %53, label %61, label %54
54: ; preds = %45
%55 = load i32, i32* %7
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = icmp ne i32 %55, %59
br i1 %60, label %61, label %66
61: ; preds = %54, %45
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = load i32, i32* %5
%65 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %62, i32 %63, i32 %64)
br label %66
66: ; preds = %61, %54
br label %67
67: ; preds = %66
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
store i32 %69, i32* %4
br label %11
70: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [62 x i8] c"sigref_cal_to_accumid error sr=%d cal=%d acc=%d, expected=%d\0A\00"
@.str.1 = [49 x i8] c"accumid_to_sigref_cal error sr=%d cal=%d acc=%d\0A\00"
define void @test_conversions() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sigref_cal_to_accumid(i32 1, i32 0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 1, i32 0, i32 %5, i32 1)
br label %9
9: ; preds = %7, %0
%10 = call i32 @accumid_to_sigref_cal(i32 %5, i32* %1, i32* %2)
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 1
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13, i32 %5)
br label %18
18: ; preds = %9, %16
%19 = call i32 @sigref_cal_to_accumid(i32 1, i32 1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 1, i32 1, i32 %19, i32 0)
br label %23
23: ; preds = %21, %18
%24 = call i32 @accumid_to_sigref_cal(i32 %19, i32* %1, i32* %2)
%25 = load i32, i32* %1
%26 = icmp eq i32 %25, 1
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 1
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %27, i32 %19)
br label %32
32: ; preds = %30, %23
%33 = call i32 @sigref_cal_to_accumid(i32 0, i32 0)
%34 = icmp eq i32 %33, 3
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 0, i32 0, i32 %33, i32 3)
br label %37
37: ; preds = %35, %32
%38 = call i32 @accumid_to_sigref_cal(i32 %33, i32* %1, i32* %2)
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, 0
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, 0
%43 = select i1 %40, i1 %42, i1 false
br i1 %43, label %46, label %44
44: ; preds = %37
%45 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %41, i32 %33)
br label %46
46: ; preds = %44, %37
%47 = call i32 @sigref_cal_to_accumid(i32 0, i32 1)
%48 = icmp eq i32 %47, 2
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 0, i32 1, i32 %47, i32 2)
br label %51
51: ; preds = %49, %46
%52 = call i32 @accumid_to_sigref_cal(i32 %47, i32* %1, i32* %2)
%53 = load i32, i32* %1
%54 = icmp eq i32 %53, 0
%55 = load i32, i32* %2
%56 = icmp eq i32 %55, 1
%57 = select i1 %54, i1 %56, i1 false
br i1 %57, label %60, label %58
58: ; preds = %51
%59 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %53, i32 %55, i32 %47)
br label %60
60: ; preds = %58, %51
ret void
}