#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 */
struct move_t {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int valid_input(char *, struct move_t *);
int read_move(FILE *input, struct move_t *move) {
  char *line = 0;
  size_t n = 0;
  ssize_t ret;
  ret = getline(&line, &n, input);
  if (ret >= 1) {
    if (line[ret - 1] == '\n') {
      line[ret - 1] = 0;
    }
    ret = valid_input(line, move);
    free(line);
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     11b2 <read_move+0x82>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1199 <read_move+0x69>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <valid_input@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_move>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <getline@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    118f <read_move+0x5f>
mov    0x8(%rsp),%rdi
add    $0xffffffff,%ebx
cmpb   $0xa,(%rdi,%rbx,1)
jne    117b <read_move+0x4b>
movb   $0x0,(%rdi,%rbx,1)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1040 <valid_input@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.move_t = type { i32 }
define i32 @read_move(i32* %0, %struct.move_t* %1) {
%3 = alloca i32*
%4 = alloca %struct.move_t*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
store %struct.move_t* %1, %struct.move_t** %4
store i8* null, i8** %5
store i64 0, i64* %6
%8 = load i32*, i32** %3
%9 = call i32 @getline(i8** %5, i64* %6, i32* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp sge i32 %10, 1
br i1 %11, label %12, label %33
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %27
21: ; preds = %12
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %21, %12
%28 = load i8*, i8** %5
%29 = load %struct.move_t*, %struct.move_t** %4
%30 = call i32 @valid_input(i8* %28, %struct.move_t* %29)
store i32 %30, i32* %7
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %27, %2
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
%struct.move_t = type { i32 }
define i32 @read_move(i32* %0, %struct.move_t* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = call i32 @getline(i8** %3, i64* %4, i32* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = add nsw i32 %7, -1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %9
store i8 0, i8* %13
%17 = load i8*, i8** %3
br label %18
18: ; preds = %16, %9
%19 = phi i8* [ %17, %16 ], [ %10, %9 ]
%20 = call i32 @valid_input(i8* %19, %struct.move_t* %1)
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %18, %2
%24 = phi i32 [ %20, %18 ], [ %7, %2 ]
ret i32 %24
}