#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 *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *skip_whitespace(char const *);
char *read_key(const char *line) {
  int pos = 0;
  char *result;
  line = skip_whitespace(line);
  for (; line[pos] != ' ' && line[pos] != '\0' && line[pos] != '\t'; ++pos) {
  }
  result = calloc(pos + 1, sizeof(char));
  memcpy(result, line, pos * sizeof(char));
  result[pos] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<read_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespace@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     1199 <read_key+0x69>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1199 <read_key+0x69>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a9 <read_key+0x79>
jmp    11bc <read_key+0x8c>
jmp    11ae <read_key+0x7e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <read_key+0x20>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1030 <skip_whitespace@plt>
mov    %rax,%r14
xor    %ebx,%ebx
movabs $0x100000201,%rax
jmp    1154 <read_key+0x24>
xchg   %ax,%ax
add    $0x1,%rbx
movzbl (%r14,%rbx,1),%ecx
cmp    $0x20,%rcx
ja     1150 <read_key+0x20>
bt     %rcx,%rax
jae    1150 <read_key+0x20>
mov    %ebx,%r12d
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @read_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i8* @skip_whitespace(i8* %5)
store i8* %6, i8** %2
br label %7
7: ; preds = %34, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 32
br i1 %14, label %15, label %31
15: ; preds = %7
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 9
br label %31
31: ; preds = %23, %15, %7
%32 = phi i1 [ false, %15 ], [ false, %7 ], [ %30, %23 ]
br i1 %32, label %33, label %37
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %7
37: ; preds = %31
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
%40 = call i8* @calloc(i32 %39, i32 1)
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = mul i64 %44, 1
%46 = trunc i64 %45 to i32
%47 = call i32 @memcpy(i8* %41, i8* %42, i32 %46)
%48 = load i8*, i8** %4
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %4
ret i8* %52
}

LLVM IR (-O2):
define i8* @read_key(i8* %0) {
%2 = tail call i8* @skip_whitespace(i8* %0)
br label %3
3: ; preds = %7, %1
%4 = phi i64 [ %8, %7 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 32, label %9
i8 0, label %9
i8 9, label %9
]
7: ; preds = %3
%8 = add nuw i64 %4, 1
br label %3
9: ; preds = %3, %3, %3
%10 = trunc i64 %4 to i32
%11 = and i64 %4, 4294967295
%12 = add nuw nsw i32 %10, 1
%13 = tail call i8* @calloc(i32 %12, i32 1)
%14 = tail call i32 @memcpy(i8* %13, i8* %2, i32 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %11
store i8 0, i8* %15
ret i8* %13
}