#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int read_column(void) {
  char buf[256];
  printf("Enter a column number [1, %d]\n", (7));
  while (fgets(buf, sizeof(buf), stdin)) {
    int column;
    if (sscanf(buf, "%d", &column) == 1) {
      if (column >= 1 && column <= (7)) {
        return column - 1;
      } else {
        printf("Column number must be in range [1, %d]\n", (7));
      }
    } else {
      printf("Please enter a number\n");
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<read_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xebe(%rip),%rdi
mov    $0x7,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11eb <read_column+0xbb>
lea    -0x110(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    -0x114(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11d8 <read_column+0xa8>
cmpl   $0x1,-0x114(%rbp)
jl     11c0 <read_column+0x90>
cmpl   $0x7,-0x114(%rbp)
jg     11c0 <read_column+0x90>
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <read_column+0xc2>
lea    0xe5b(%rip),%rdi
mov    $0x7,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e6 <read_column+0xb6>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114e <read_column+0x1e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_column>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xea8(%rip),%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e7d(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <read_column+0xbd>
lea    0xe96(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xe88(%rip),%r12
lea    0xea9(%rip),%r13
jmp    11cd <read_column+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <read_column+0xbd>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <read_column+0x70>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x6,%eax
jbe    1202 <read_column+0xc2>
mov    %r12,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b8 <read_column+0x78>
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter a column number [1, %d]\0A\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Column number must be in range [1, %d]\0A\00"
@.str.3 = [23 x i8] c"Please enter a number\0A\00"
define i32 @read_column() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 7)
br label %5
5: ; preds = %28, %0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i64 @fgets(i8* %6, i32 256, i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %5
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i32, i32* %3
%16 = icmp sge i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* %3
%19 = icmp sle i32 %18, 7
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %1
br label %30
23: ; preds = %17, %14
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %25
25: ; preds = %23
br label %28
26: ; preds = %10
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
br label %5
29: ; preds = %5
store i32 -1, i32* %1
br label %30
30: ; preds = %29, %20
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [31 x i8] c"Enter a column number [1, %d]\0A\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Column number must be in range [1, %d]\0A\00"
@str = [22 x i8] c"Please enter a number\00"
define i32 @read_column() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 7)
%5 = load i32, i32* @stdin
%6 = call i64 @fgets(i8* %3, i32 256, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %0
%9 = bitcast i32* %2 to i8*
br label %10
10: ; preds = %8, %22
%11 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %2
%15 = add i32 %14, -1
%16 = icmp ult i32 %15, 7
br i1 %16, label %17, label %18
17: ; preds = %13
br label %26
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %22
20: ; preds = %10
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %18, %20
%23 = load i32, i32* @stdin
%24 = call i64 @fgets(i8* %3, i32 256, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %10
26: ; preds = %22, %0, %17
%27 = phi i32 [ %15, %17 ], [ -1, %0 ], [ -1, %22 ]
ret i32 %27
}