#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 */
scalar_t__ colour_is_black(int);
int /*<<< orphan*/ colour_is_ok(int);
int /*<<< orphan*/ my_fatal(char *, char *, int);
int /*<<< orphan*/ square_is_ok(int);
int square_rank(int);
int square_side_rank(int square, int colour) {
  int rank;
  {
    if (!(square_is_ok(square)))
      my_fatal("file \"%s\", line %d, assertion \""
               "square_is_ok(square)"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/square.c",
               101);
  };
  {
    if (!(colour_is_ok(colour)))
      my_fatal("file \"%s\", line %d, assertion \""
               "colour_is_ok(colour)"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/square.c",
               102);
  };
  rank = square_rank(square);
  if (colour_is_black(colour))
    rank = 7 - rank;
  return rank;
}


x86 assembly (clang, -O0):
<square_side_rank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <square_is_ok@plt>
cmp    $0x0,%eax
jne    1187 <square_side_rank+0x37>
lea    0xe8a(%rip),%rdi
lea    0xec0(%rip),%rsi
mov    $0x65,%edx
call   1050 <my_fatal@plt>
mov    -0x8(%rbp),%edi
call   1070 <colour_is_ok@plt>
cmp    $0x0,%eax
jne    11b0 <square_side_rank+0x60>
lea    0xf25(%rip),%rdi
lea    0xe97(%rip),%rsi
mov    $0x66,%edx
call   1050 <my_fatal@plt>
mov    -0x4(%rbp),%edi
call   1040 <square_rank@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <colour_is_black@plt>
cmp    $0x0,%rax
je     11d8 <square_side_rank+0x88>
mov    $0x7,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<square_side_rank>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1060 <square_is_ok@plt>
test   %eax,%eax
jne    1178 <square_side_rank+0x28>
lea    0xe99(%rip),%rdi
lea    0xecf(%rip),%rsi
mov    $0x65,%edx
call   1050 <my_fatal@plt>
mov    %ebx,%edi
call   1070 <colour_is_ok@plt>
test   %eax,%eax
jne    119b <square_side_rank+0x4b>
lea    0xf3a(%rip),%rdi
lea    0xeac(%rip),%rsi
mov    $0x66,%edx
call   1050 <my_fatal@plt>
mov    %ebp,%edi
call   1040 <square_rank@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <colour_is_black@plt>
mov    $0x7,%ecx
sub    %ebp,%ecx
test   %rax,%rax
cmove  %ebp,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"file \22%s\22, line %d, assertion \22square_is_ok(square)\22 failed\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/square.c\00"
@.str.2 = [61 x i8] c"file \22%s\22, line %d, assertion \22colour_is_ok(colour)\22 failed\0A\00"
define i32 @square_side_rank(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @square_is_ok(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @my_fatal(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 101)
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* %4
%13 = call i32 @colour_is_ok(i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @my_fatal(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 102)
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %3
%19 = call i32 @square_rank(i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %4
%21 = call i64 @colour_is_black(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* %5
%25 = sub nsw i32 7, %24
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %17
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@.str = [61 x i8] c"file \22%s\22, line %d, assertion \22square_is_ok(square)\22 failed\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/square.c\00"
@.str.2 = [61 x i8] c"file \22%s\22, line %d, assertion \22colour_is_ok(colour)\22 failed\0A\00"
define i32 @square_side_rank(i32 %0, i32 %1) {
%3 = tail call i32 @square_is_ok(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @my_fatal(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 101)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @colour_is_ok(i32 %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @my_fatal(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 102)
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @square_rank(i32 %0)
%14 = tail call i64 @colour_is_black(i32 %1)
%15 = icmp eq i64 %14, 0
%16 = sub nsw i32 7, %13
%17 = select i1 %15, i32 %13, i32 %16
ret i32 %17
}