#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 */
char getch();
int /*<<< orphan*/ printf(char *);
void pawnPromotion(char grid[8][8][33], char pieceTranslator[33]) {
  int x;
  char promotion;
  for (x = 0; x < 8; ++x) {
    if (pieceTranslator[(int)grid[x][0][0]] == 'p') {
      do {
        printf("\nChoose what the pawn promotes to (q, b, n or r): ");
        promotion = getch();
      } while ((promotion != 'q') && (promotion != 'b') && (promotion != 'n') &&
               (promotion != 'r'));
      pieceTranslator[(int)grid[x][0][0]] = promotion;
    } else if (pieceTranslator[(int)grid[x][7][0]] == 'P') {
      do {
        printf("\nChoose what the pawn promotes to (Q, B, N or R): ");
        promotion = getch();
      } while ((promotion != 'Q') && (promotion != 'B') && (promotion != 'N') &&
               (promotion != 'R'));
      pieceTranslator[(int)grid[x][7][0]] = promotion;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<pawnPromotion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    12ce <pawnPromotion+0x1ae>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
imul   $0x108,%rdx,%rdx
add    %rdx,%rcx
movsbl (%rcx),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x70,%eax
jne    11fa <pawnPromotion+0xda>
jmp    116f <pawnPromotion+0x4f>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x16(%rbp)
je     11c8 <pawnPromotion+0xa8>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x62,%ecx
mov    %al,-0x16(%rbp)
je     11c8 <pawnPromotion+0xa8>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x6e,%ecx
mov    %al,-0x16(%rbp)
je     11c8 <pawnPromotion+0xa8>
movsbl -0x15(%rbp),%eax
cmp    $0x72,%eax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    116f <pawnPromotion+0x4f>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rsi
imul   $0x108,%rsi,%rsi
add    %rsi,%rcx
movsbl (%rcx),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12bb <pawnPromotion+0x19b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
imul   $0x108,%rdx,%rdx
add    %rdx,%rcx
movsbl 0xe7(%rcx),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x50,%eax
jne    12b6 <pawnPromotion+0x196>
jmp    122c <pawnPromotion+0x10c>
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x51,%ecx
mov    %al,-0x17(%rbp)
je     1285 <pawnPromotion+0x165>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x42,%ecx
mov    %al,-0x17(%rbp)
je     1285 <pawnPromotion+0x165>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x4e,%ecx
mov    %al,-0x17(%rbp)
je     1285 <pawnPromotion+0x165>
movsbl -0x15(%rbp),%eax
cmp    $0x52,%eax
setne  %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
test   $0x1,%al
jne    122c <pawnPromotion+0x10c>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rsi
imul   $0x108,%rsi,%rsi
add    %rsi,%rcx
movsbl 0xe7(%rcx),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12bb <pawnPromotion+0x19b>
jmp    12c0 <pawnPromotion+0x1a0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <pawnPromotion+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pawnPromotion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec8(%rip),%r15
mov    $0x19001,%r13d
xor    %ebp,%ebp
jmp    1167 <pawnPromotion+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbq (%r12),%rcx
mov    %al,(%r14,%rcx,1)
add    $0x1,%rbp
cmp    $0x8,%rbp
je     1209 <pawnPromotion+0xe9>
mov    %rbp,%rax
shl    $0x8,%rax
lea    (%rax,%rbp,8),%r12
movsbq (%rbx,%r12,1),%rax
cmpb   $0x70,(%r14,%rax,1)
jne    11c0 <pawnPromotion+0xa0>
add    %rbx,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getch@plt>
lea    -0x62(%rax),%ecx
cmp    $0x10,%cl
ja     1190 <pawnPromotion+0x70>
movzbl %cl,%ecx
bt     %rcx,%r13
jae    1190 <pawnPromotion+0x70>
jmp    1150 <pawnPromotion+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbq 0xe7(%rbx,%r12,1),%rax
cmpb   $0x50,(%r14,%rax,1)
jne    1159 <pawnPromotion+0x39>
add    %rbx,%r12
add    $0xe7,%r12
nopw   0x0(%rax,%rax,1)
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getch@plt>
lea    -0x42(%rax),%ecx
cmp    $0x10,%cl
ja     11e0 <pawnPromotion+0xc0>
movzbl %cl,%ecx
bt     %rcx,%r13
jae    11e0 <pawnPromotion+0xc0>
jmp    1150 <pawnPromotion+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\0AChoose what the pawn promotes to (q, b, n or r): \00"
@.str.1 = [51 x i8] c"\0AChoose what the pawn promotes to (Q, B, N or R): \00"
define void @pawnPromotion([8 x [33 x i8]]* %0, i8* %1) {
%3 = alloca [8 x [33 x i8]]*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store [8 x [33 x i8]]* %0, [8 x [33 x i8]]** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %112, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %115
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %12, i64 %14
%16 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %15, i64 0, i64 0
%17 = getelementptr inbounds [33 x i8], [33 x i8]* %16, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %11, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 112
br i1 %24, label %25, label %60
25: ; preds = %10
br label %26
26: ; preds = %45, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%28 = call signext i8 (...) @getch()
store i8 %28, i8* %6
br label %29
29: ; preds = %26
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 113
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 98
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load i8, i8* %6
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 110
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 114
br label %45
45: ; preds = %41, %37, %33, %29
%46 = phi i1 [ false, %37 ], [ false, %33 ], [ false, %29 ], [ %44, %41 ]
br i1 %46, label %26, label %47
47: ; preds = %45
%48 = load i8, i8* %6
%49 = load i8*, i8** %4
%50 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %50, i64 %52
%54 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %53, i64 0, i64 0
%55 = getelementptr inbounds [33 x i8], [33 x i8]* %54, i64 0, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %49, i64 %58
store i8 %48, i8* %59
br label %111
60: ; preds = %10
%61 = load i8*, i8** %4
%62 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %62, i64 %64
%66 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %65, i64 0, i64 7
%67 = getelementptr inbounds [33 x i8], [33 x i8]* %66, i64 0, i64 0
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %61, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 80
br i1 %74, label %75, label %110
75: ; preds = %60
br label %76
76: ; preds = %95, %75
%77 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%78 = call signext i8 (...) @getch()
store i8 %78, i8* %6
br label %79
79: ; preds = %76
%80 = load i8, i8* %6
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %81, 81
br i1 %82, label %83, label %95
83: ; preds = %79
%84 = load i8, i8* %6
%85 = sext i8 %84 to i32
%86 = icmp ne i32 %85, 66
br i1 %86, label %87, label %95
87: ; preds = %83
%88 = load i8, i8* %6
%89 = sext i8 %88 to i32
%90 = icmp ne i32 %89, 78
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = load i8, i8* %6
%93 = sext i8 %92 to i32
%94 = icmp ne i32 %93, 82
br label %95
95: ; preds = %91, %87, %83, %79
%96 = phi i1 [ false, %87 ], [ false, %83 ], [ false, %79 ], [ %94, %91 ]
br i1 %96, label %76, label %97
97: ; preds = %95
%98 = load i8, i8* %6
%99 = load i8*, i8** %4
%100 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%101 = load i32, i32* %5
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %100, i64 %102
%104 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %103, i64 0, i64 7
%105 = getelementptr inbounds [33 x i8], [33 x i8]* %104, i64 0, i64 0
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %99, i64 %108
store i8 %98, i8* %109
br label %110
110: ; preds = %97, %60
br label %111
111: ; preds = %110, %47
br label %112
112: ; preds = %111
%113 = load i32, i32* %5
%114 = add nsw i32 %113, 1
store i32 %114, i32* %5
br label %7
115: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"\0AChoose what the pawn promotes to (q, b, n or r): \00"
@.str.1 = [51 x i8] c"\0AChoose what the pawn promotes to (Q, B, N or R): \00"
define void @pawnPromotion([8 x [33 x i8]]* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %2, %30
%4 = phi i64 [ 0, %2 ], [ %31, %30 ]
%5 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %0, i64 %4, i64 0, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 112
br i1 %10, label %11, label %14
11: ; preds = %3, %11
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%13 = tail call signext i8 (...) @getch()
switch i8 %13, label %11 [
i8 114, label %24
i8 113, label %24
i8 110, label %24
i8 98, label %24
]
14: ; preds = %3
%15 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %0, i64 %4, i64 7, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 80
br i1 %20, label %21, label %30
21: ; preds = %14, %21
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call signext i8 (...) @getch()
switch i8 %23, label %21 [
i8 82, label %24
i8 81, label %24
i8 78, label %24
i8 66, label %24
]
24: ; preds = %21, %21, %21, %21, %11, %11, %11, %11
%25 = phi i8* [ %5, %11 ], [ %5, %11 ], [ %5, %11 ], [ %5, %11 ], [ %15, %21 ], [ %15, %21 ], [ %15, %21 ], [ %15, %21 ]
%26 = phi i8 [ %13, %11 ], [ %13, %11 ], [ %13, %11 ], [ %13, %11 ], [ %23, %21 ], [ %23, %21 ], [ %23, %21 ], [ %23, %21 ]
%27 = load i8, i8* %25
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %24, %14
%31 = add nuw nsw i64 %4, 1
%32 = icmp eq i64 %31, 8
br i1 %32, label %33, label %3
33: ; preds = %30
ret void
}