#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*/ display_game_area(int, int);
char getch();
int select_column(int startcolumn) {
  int column = startcolumn;
  char selection;
  while ((selection = getch()) != '\n') {
    switch (selection) {
    case 68: {
      if (column > 0) {
        column--;
        display_game_area(column, -1);
      }
      break;
    }
    case 67: {
      if (column < 8 - 1) {
        column++;
        display_game_area(column, -1);
      }
      break;
    }
    default: {
      break;
    }
    }
  }
  return column;
}


x86 assembly (clang, -O0):
<select_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getch@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11c1 <select_column+0xa1>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x43,%eax
je     1192 <select_column+0x72>
jmp    115c <select_column+0x3c>
mov    -0x10(%rbp),%eax
sub    $0x44,%eax
jne    11b7 <select_column+0x97>
jmp    116d <select_column+0x4d>
cmpl   $0x0,-0x8(%rbp)
jle    118d <select_column+0x6d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <display_game_area@plt>
jmp    11bc <select_column+0x9c>
cmpl   $0x7,-0x8(%rbp)
jge    11b2 <select_column+0x92>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <display_game_area@plt>
jmp    11bc <select_column+0x9c>
jmp    11bc <select_column+0x9c>
jmp    1131 <select_column+0x11>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_column>:
push   %rbx
mov    %edi,%ebx
jmp    1147 <select_column+0x27>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xffffffff,%eax
test   %ebx,%ebx
jle    1147 <select_column+0x27>
add    %eax,%ebx
mov    %ebx,%edi
mov    $0xffffffff,%esi
call   1040 <display_game_area@plt>
xor    %eax,%eax
call   1030 <getch@plt>
cmp    $0xa,%al
je     117c <select_column+0x5c>
movsbl %al,%eax
cmp    $0x43,%eax
je     1170 <select_column+0x50>
cmp    $0x44,%eax
je     1130 <select_column+0x10>
jmp    1147 <select_column+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%eax
cmp    $0x6,%ebx
jg     1147 <select_column+0x27>
jmp    1139 <select_column+0x19>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @select_column(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = load i32, i32* %2
store i32 %5, i32* %3
br label %6
6: ; preds = %32, %1
%7 = call signext i8 (...) @getch()
store i8 %7, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
switch i32 %12, label %31 [
i32 68, label %13
i32 67, label %22
]
13: ; preds = %10
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @display_game_area(i32 %19, i32 -1)
br label %21
21: ; preds = %16, %13
br label %32
22: ; preds = %10
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 7
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = call i32 @display_game_area(i32 %28, i32 -1)
br label %30
30: ; preds = %25, %22
br label %32
31: ; preds = %10
br label %32
32: ; preds = %31, %30, %21
br label %6
33: ; preds = %6
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @select_column(i32 %0) {
%2 = tail call signext i8 (...) @getch()
%3 = icmp eq i8 %2, 10
br i1 %3, label %20, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %18, %16 ], [ %2, %1 ]
%6 = phi i32 [ %17, %16 ], [ %0, %1 ]
%7 = sext i8 %5 to i32
switch i32 %7, label %16 [
i32 68, label %8
i32 67, label %10
]
8: ; preds = %4
%9 = icmp sgt i32 %6, 0
br i1 %9, label %12, label %16
10: ; preds = %4
%11 = icmp slt i32 %6, 7
br i1 %11, label %12, label %16
12: ; preds = %10, %8
%13 = phi i32 [ -1, %8 ], [ 1, %10 ]
%14 = add nsw i32 %6, %13
%15 = tail call i32 @display_game_area(i32 %14, i32 -1)
br label %16
16: ; preds = %12, %4, %10, %8
%17 = phi i32 [ %6, %4 ], [ %6, %10 ], [ %6, %8 ], [ %14, %12 ]
%18 = tail call signext i8 (...) @getch()
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %4
20: ; preds = %16, %1
%21 = phi i32 [ %0, %1 ], [ %17, %16 ]
ret i32 %21
}