#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 getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int check_input_string(char *string, int type) {
  int ref_length;
  if (type == 0)
    ref_length = 32;
  else if (type == 1)
    ref_length = 512;
  int total_length = strlen(string);
  if (total_length == 1)
    return -1;
  if (total_length == ref_length - 1 && (string[ref_length - 2] != '\n')) {
    int count_stream_char = 1;
    while (getc(stdin) != '\n')
      count_stream_char++;
    if (count_stream_char != 1)
      printf("WARNING: Input string exceeds maximum length. The message was "
             "cut.\n");
  }
  if (string[total_length - 1] == '\n')
    string[total_length - 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<check_input_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1155 <check_input_string+0x25>
movl   $0x20,-0x18(%rbp)
jmp    116b <check_input_string+0x3b>
cmpl   $0x1,-0x14(%rbp)
jne    1166 <check_input_string+0x36>
movl   $0x200,-0x18(%rbp)
jmp    116b <check_input_string+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    118d <check_input_string+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <check_input_string+0x104>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1202 <check_input_string+0xd2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1202 <check_input_string+0xd2>
movl   $0x1,-0x20(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11e7 <check_input_string+0xb7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bf <check_input_string+0x8f>
cmpl   $0x1,-0x20(%rbp)
je     11fd <check_input_string+0xcd>
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
jmp    1202 <check_input_string+0xd2>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    122d <check_input_string+0xfd>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_input_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%esi
mov    $0x200,%eax
mov    $0x20,%ebx
cmove  %eax,%ebx
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    $0xffffffff,%eax
cmp    $0x1,%r15d
je     11b2 <check_input_string+0x82>
lea    -0x1(%rbx),%eax
cmp    %eax,%r15d
jne    119f <check_input_string+0x6f>
add    $0xfffffffe,%ebx
cmpb   $0xa,(%r14,%rbx,1)
je     119f <check_input_string+0x6f>
mov    $0x1,%ebx
mov    0x2e6d(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   1050 <getc@plt>
add    $0xffffffff,%ebx
cmp    $0xa,%al
jne    1180 <check_input_string+0x50>
test   %ebx,%ebx
je     119f <check_input_string+0x6f>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
movslq %r15d,%rcx
xor    %eax,%eax
cmpb   $0xa,-0x1(%rcx,%r14,1)
jne    11b2 <check_input_string+0x82>
movb   $0x0,-0x1(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [68 x i8] c"WARNING: Input string exceeds maximum length. The message was cut.\0A\00"
define i32 @check_input_string(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 32, i32* %6
br label %17
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 512, i32* %6
br label %16
16: ; preds = %15, %12
br label %17
17: ; preds = %16, %11
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %3
br label %68
23: ; preds = %17
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = icmp eq i32 %24, %26
br i1 %27, label %28, label %52
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %52
37: ; preds = %28
store i32 1, i32* %8
br label %38
38: ; preds = %43, %37
%39 = load i32, i32* @stdin
%40 = call signext i8 @getc(i32 %39)
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %38
46: ; preds = %38
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
br label %52
52: ; preds = %51, %28, %23
%53 = load i8*, i8** %4
%54 = load i32, i32* %7
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 10
br i1 %60, label %61, label %67
61: ; preds = %52
%62 = load i8*, i8** %4
%63 = load i32, i32* %7
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %61, %52
store i32 0, i32* %3
br label %68
68: ; preds = %67, %22
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [67 x i8] c"WARNING: Input string exceeds maximum length. The message was cut.\00"
define i32 @check_input_string(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 1
%4 = select i1 %3, i32 512, i32 32
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %33, label %7
7: ; preds = %2
%8 = add nsw i32 %4, -1
%9 = icmp eq i32 %5, %8
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = add nsw i32 %4, -2
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %26, label %16
16: ; preds = %10, %16
%17 = phi i32 [ %21, %16 ], [ 1, %10 ]
%18 = load i32, i32* @stdin
%19 = tail call signext i8 @getc(i32 %18)
%20 = icmp eq i8 %19, 10
%21 = add nuw nsw i32 %17, 1
br i1 %20, label %22, label %16
22: ; preds = %16
%23 = icmp eq i32 %17, 1
br i1 %23, label %26, label %24
24: ; preds = %22
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %22, %24, %10, %7
%27 = add nsw i32 %5, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 10
br i1 %31, label %32, label %33
32: ; preds = %26
store i8 0, i8* %29
br label %33
33: ; preds = %26, %32, %2
%34 = phi i32 [ -1, %2 ], [ 0, %32 ], [ 0, %26 ]
ret i32 %34
}