#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 /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  int value = 0;
  int charcount = 0;
  int factor = 1;
  printf("Give a number ");
  while ((i = getchar()) != '\n') {
    charcount++;
    if (i == 43 && charcount == 1)
      continue;
    else if (i == 45 && charcount == 1) {
      factor = -1;
      continue;
    } else if (i >= 48 && i <= 57) {
      value = 10 * value + (i - 48);
      continue;
    } else if (((i == 43) || (i == 45)) && (charcount > 1))
      printf("'%c' only allowed as first character!\n", i);
    else
      printf("Invalid input!\n");
    factor = 1;
    while (getchar() != '\n')
      ;
    charcount = 0;
    value = 0;
    printf("Give a number ");
  }
  printf("%d\n", value * factor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x8(%rbp)
cmp    $0xa,%eax
je     1263 <main+0x143>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x2b,-0x8(%rbp)
jne    118a <main+0x6a>
cmpl   $0x1,-0x10(%rbp)
jne    118a <main+0x6a>
jmp    1152 <main+0x32>
cmpl   $0x2d,-0x8(%rbp)
jne    11aa <main+0x8a>
cmpl   $0x1,-0x10(%rbp)
jne    11aa <main+0x8a>
movl   $0xffffffff,-0x14(%rbp)
jmp    1152 <main+0x32>
cmpl   $0x30,-0x8(%rbp)
jl     11d2 <main+0xb2>
cmpl   $0x39,-0x8(%rbp)
jg     11d2 <main+0xb2>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x32>
cmpl   $0x2b,-0x8(%rbp)
je     11e6 <main+0xc6>
cmpl   $0x2d,-0x8(%rbp)
jne    1206 <main+0xe6>
cmpl   $0x1,-0x10(%rbp)
jle    1206 <main+0xe6>
mov    -0x8(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xf4>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <main+0xf9>
jmp    121e <main+0xfe>
jmp    1223 <main+0x103>
movl   $0x1,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1242 <main+0x122>
jmp    122a <main+0x10a>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1152 <main+0x32>
mov    -0xc(%rbp),%esi
imul   -0x14(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
lea    0xeb7(%rip),%r14
lea    0xedb(%rip),%r15
xor    %r13d,%r13d
xor    %ecx,%ecx
mov    %ebp,%edx
mov    %edx,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1202 <main+0xd2>
cmp    $0x2b,%al
jne    118e <main+0x5e>
mov    $0x1,%ecx
test   %ebx,%ebx
je     1170 <main+0x40>
cmp    $0x2d,%al
jne    11a0 <main+0x70>
mov    $0xffffffff,%edx
mov    $0x1,%ecx
test   %ebx,%ebx
je     1166 <main+0x36>
movsbl %al,%esi
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     11bf <main+0x8f>
add    $0x1,%ebx
lea    0x0(%r13,%r13,4),%eax
lea    (%rsi,%rax,2),%r13d
add    $0xffffffd0,%r13d
mov    %ebx,%ecx
jmp    1164 <main+0x34>
add    $0xd5,%al
test   $0xfd,%al
jne    11d5 <main+0xa5>
test   %ebx,%ebx
jle    11d5 <main+0xa5>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <main+0xb0>
mov    %r15,%rdi
call   1030 <puts@plt>
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11e0 <main+0xb0>
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    1162 <main+0x32>
imul   %r13d,%ebp
lea    0xe29(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Give a number \00"
@.str.1 = [39 x i8] c"'%c' only allowed as first character!\0A\00"
@.str.2 = [16 x i8] c"Invalid input!\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %62, %33, %26, %19, %0
%8 = call signext i8 (...) @getchar()
%9 = sext i8 %8 to i32
store i32 %9, i32* %2
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %64
11: ; preds = %7
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 43
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16
br label %7
20: ; preds = %16, %11
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 -1, i32* %5
br label %7
27: ; preds = %23, %20
%28 = load i32, i32* %2
%29 = icmp sge i32 %28, 48
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %2
%32 = icmp sle i32 %31, 57
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %3
%35 = mul nsw i32 10, %34
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 48
%38 = add nsw i32 %35, %37
store i32 %38, i32* %3
br label %7
39: ; preds = %30, %27
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, 43
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %2
%44 = icmp eq i32 %43, 45
br i1 %44, label %45, label %51
45: ; preds = %42, %39
%46 = load i32, i32* %4
%47 = icmp sgt i32 %46, 1
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %2
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %53
51: ; preds = %45, %42
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
store i32 1, i32* %5
br label %57
57: ; preds = %61, %56
%58 = call signext i8 (...) @getchar()
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 10
br i1 %60, label %61, label %62
61: ; preds = %57
br label %57
62: ; preds = %57
store i32 0, i32* %4
store i32 0, i32* %3
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
64: ; preds = %7
%65 = load i32, i32* %3
%66 = load i32, i32* %5
%67 = mul nsw i32 %65, %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Give a number \00"
@.str.1 = [39 x i8] c"'%c' only allowed as first character!\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [15 x i8] c"Invalid input!\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %29, %0
%3 = phi i32 [ 0, %0 ], [ %30, %29 ]
%4 = phi i32 [ 0, %0 ], [ %31, %29 ]
%5 = phi i32 [ 1, %0 ], [ %32, %29 ]
br label %6
6: ; preds = %2, %17
%7 = phi i32 [ %4, %2 ], [ 1, %17 ]
%8 = phi i32 [ %5, %2 ], [ -1, %17 ]
br label %9
9: ; preds = %6, %13
%10 = phi i32 [ 1, %13 ], [ %7, %6 ]
%11 = tail call signext i8 (...) @getchar()
%12 = icmp eq i8 %11, 10
br i1 %12, label %47, label %13
13: ; preds = %9
%14 = icmp eq i8 %11, 43
%15 = icmp eq i32 %10, 0
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %9, label %17
17: ; preds = %13
%18 = icmp eq i8 %11, 45
%19 = select i1 %18, i1 %15, i1 false
br i1 %19, label %6, label %20
20: ; preds = %17
%21 = sext i8 %11 to i32
%22 = add i8 %11, -48
%23 = icmp ult i8 %22, 10
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = add nsw i32 %10, 1
%26 = mul nsw i32 %3, 10
%27 = add i32 %26, -48
%28 = add i32 %27, %21
br label %29
29: ; preds = %24, %45
%30 = phi i32 [ 0, %45 ], [ %28, %24 ]
%31 = phi i32 [ 0, %45 ], [ %25, %24 ]
%32 = phi i32 [ 1, %45 ], [ %8, %24 ]
br label %2
33: ; preds = %20
%34 = or i1 %14, %18
%35 = icmp sgt i32 %10, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %41
39: ; preds = %33
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %37, %39
br label %42
42: ; preds = %41, %42
%43 = tail call signext i8 (...) @getchar()
%44 = icmp eq i8 %43, 10
br i1 %44, label %45, label %42
45: ; preds = %42
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %29
47: ; preds = %9
%48 = mul nsw i32 %8, %3
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %48)
ret i32 0
}