#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 getchar();
int isCValidVar(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char str[1024] = {};
  int i = 0;
  printf("input a variable:\n");
  while ((str[i] = getchar()) != '\n') {
    i++;
  }
  str[i] = '\0';
  printf("\nvariable %s is %s.\n", str,
         ((isCValidVar(str) == 1) ? "valid" : "invalid"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x0,-0x414(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movslq -0x414(%rbp),%rcx
mov    %al,-0x410(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11b2 <main+0x72>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    117d <main+0x3d>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1060 <isCValidVar@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%ecx
lea    0xe3d(%rip),%rdx
lea    0xe38(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,0x1(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1180 <main+0x30>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <isCValidVar@plt>
cmp    $0x1,%eax
lea    0xe69(%rip),%rax
lea    0xe60(%rip),%rdx
cmove  %rax,%rdx
lea    0xe40(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"input a variable:\0A\00"
@.str.1 = [21 x i8] c"\0Avariable %s is %s.\0A\00"
@.str.2 = [6 x i8] c"valid\00"
@.str.3 = [8 x i8] c"invalid\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [1024 x i8]* %2 to i8*
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %13, %0
%7 = call signext i8 (...) @getchar()
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 %7, i8* %10
%11 = sext i8 %7 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %6
16: ; preds = %6
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = call i32 @isCValidVar(i8* %21)
%23 = icmp eq i32 %22, 1
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"\0Avariable %s is %s.\0A\00"
@.str.2 = [6 x i8] c"valid\00"
@.str.3 = [8 x i8] c"invalid\00"
@str = [18 x i8] c"input a variable:\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ %9, %4 ], [ 0, %0 ]
%6 = tail call signext i8 (...) @getchar()
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %5
store i8 %6, i8* %7
%8 = icmp eq i8 %6, 10
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = and i64 %5, 4294967295
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @isCValidVar(i8* %2)
%14 = icmp eq i32 %13, 1
%15 = select i1 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %15)
ret i32 0
}