#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 convert_to_integer(char *, int);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
main() {
  int i = 0;
  char s[1000], c;
  while ((c = getchar()) != '\n')
    s[i++] = c;
  s[i] = '\0';
  convert_to_integer(s, i) == -1
      ? printf("ERROR IN INPUT\n")
      : printf("%d \t value in integer", convert_to_integer(s, i));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x3f1(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1181 <main+0x51>
mov    -0x3f1(%rbp),%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0x3f0(%rbp,%rax,1)
jmp    1149 <main+0x19>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <convert_to_integer@plt>
cmp    $0xffffffff,%eax
jne    11b8 <main+0x88>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <main+0xa7>
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <convert_to_integer@plt>
mov    %eax,%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x3f0,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1172 <main+0x32>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1160 <main+0x20>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %ebx,%esi
call   1060 <convert_to_integer@plt>
cmp    $0xffffffff,%eax
je     11a3 <main+0x63>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1060 <convert_to_integer@plt>
lea    0xe68(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11af <main+0x6f>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ERROR IN INPUT\0A\00"
@.str.1 = [22 x i8] c"%d \09 value in integer\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %9, %0
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %4
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = load i8, i8* %4
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %13
store i8 %10, i8* %14
br label %5
15: ; preds = %5
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* %2
%21 = call i32 @convert_to_integer(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %30
25: ; preds = %15
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%27 = load i32, i32* %2
%28 = call i32 @convert_to_integer(i8* %26, i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %25, %23
%31 = phi i32 [ %24, %23 ], [ %29, %25 ]
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"%d \09 value in integer\00"
@str = [15 x i8] c"ERROR IN INPUT\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 10
br i1 %4, label %14, label %5
5: ; preds = %0, %5
%6 = phi i64 [ %8, %5 ], [ 0, %0 ]
%7 = phi i8 [ %10, %5 ], [ %3, %0 ]
%8 = add nuw i64 %6, 1
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %6
store i8 %7, i8* %9
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = trunc i64 %8 to i32
br label %14
14: ; preds = %12, %0
%15 = phi i32 [ 0, %0 ], [ %13, %12 ]
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @convert_to_integer(i8* %2, i32 %15)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %25
22: ; preds = %14
%23 = call i32 @convert_to_integer(i8* %2, i32 %15)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %20
ret i32 0
}