#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*/ fgets(char *, int const, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int const strlen(char *);
int /*<<< orphan*/ system(char *);
void char_input(char *string, const int size) {
  fgets(string, size, stdin);
  string[strcspn(string, "\r\n")] = '\0';
  if (strlen(string) == size - 1) {
    while (getchar() != '\n') {
    }
  }
  system("cls");
}


x86 assembly (clang, -O0):
<char_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11d0 <char_input+0x80>
jmp    11b3 <char_input+0x63>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11cb <char_input+0x7b>
jmp    11b3 <char_input+0x63>
jmp    11d0 <char_input+0x80>
lea    0xe2c(%rip),%rdi
call   1040 <system@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_input>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jne    119b <char_input+0x4b>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1190 <char_input+0x40>
lea    0xe61(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <system@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [4 x i8] c"cls\00"
define void @char_input(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = load i32, i32* %4
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %5, i32 %6, i32 %7)
%9 = load i8*, i8** %3
%10 = load i8*, i8** %3
%11 = call i64 @strcspn(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = icmp eq i32 %14, %16
br i1 %17, label %18, label %25
18: ; preds = %2
br label %19
19: ; preds = %23, %18
%20 = call signext i8 (...) @getchar()
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %19
br label %19
24: ; preds = %19
br label %25
25: ; preds = %24, %2
%26 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [4 x i8] c"cls\00"
define void @char_input(i8* %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32 %3)
%5 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %6
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %1, -1
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %2, %10
%11 = tail call signext i8 (...) @getchar()
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %10
13: ; preds = %10, %2
%14 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}