#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 inbyte();
int /*<<< orphan*/ outbyte(char);
int /*<<< orphan*/ sml_printf(char *, ...);
int get_count_ip() {
  int loops = 0;
  int c;
  sml_printf("Enter loop count: ");
  while ((c = inbyte()) != 0x0a) {
    sml_printf("%c", c);
    if (c >= '0' && c <= '9') {
      loops *= 10;
      loops += c - '0';
    } else {
      break;
    }
  }
  outbyte('\n');
  return loops;
}


x86 assembly (clang, -O0):
<get_count_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <sml_printf@plt>
mov    $0x0,%al
call   1040 <inbyte@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xa,%eax
je     11a7 <get_count_ip+0x77>
mov    -0x8(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <sml_printf@plt>
cmpl   $0x30,-0x8(%rbp)
jl     119d <get_count_ip+0x6d>
cmpl   $0x39,-0x8(%rbp)
jg     119d <get_count_ip+0x6d>
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <get_count_ip+0x72>
jmp    11a7 <get_count_ip+0x77>
jmp    114d <get_count_ip+0x1d>
mov    $0xa,%edi
call   1050 <outbyte@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_count_ip>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <sml_printf@plt>
xor    %eax,%eax
call   1040 <inbyte@plt>
cmp    $0xa,%eax
je     118a <get_count_ip+0x5a>
mov    %eax,%ebx
lea    0xeb8(%rip),%r15
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <sml_printf@plt>
add    $0xffffffd0,%ebx
cmp    $0x9,%ebx
ja     118a <get_count_ip+0x5a>
lea    (%r14,%r14,4),%eax
lea    (%rbx,%rax,2),%r14d
xor    %eax,%eax
call   1040 <inbyte@plt>
mov    %eax,%ebx
cmp    $0xa,%eax
jne    1160 <get_count_ip+0x30>
mov    $0xa,%edi
call   1050 <outbyte@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter loop count: \00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @get_count_ip() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @sml_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %23, %0
%5 = call i32 (...) @inbyte()
store i32 %5, i32* %2
%6 = icmp ne i32 %5, 10
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @sml_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = icmp sge i32 %10, 48
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 57
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %1
%17 = mul nsw i32 %16, 10
store i32 %17, i32* %1
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 48
%20 = load i32, i32* %1
%21 = add nsw i32 %20, %19
store i32 %21, i32* %1
br label %23
22: ; preds = %12, %7
br label %24
23: ; preds = %15
br label %4
24: ; preds = %22, %4
%25 = call i32 @outbyte(i8 signext 10)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter loop count: \00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @get_count_ip() {
%1 = tail call i32 (i8*, ...) @sml_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @inbyte()
%3 = icmp eq i32 %2, 10
br i1 %3, label %15, label %4
4: ; preds = %0, %10
%5 = phi i32 [ %13, %10 ], [ %2, %0 ]
%6 = phi i32 [ %12, %10 ], [ 0, %0 ]
%7 = tail call i32 (i8*, ...) @sml_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%8 = add i32 %5, -48
%9 = icmp ult i32 %8, 10
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = mul nsw i32 %6, 10
%12 = add nsw i32 %8, %11
%13 = tail call i32 (...) @inbyte()
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %4
15: ; preds = %10, %4, %0
%16 = phi i32 [ 0, %0 ], [ %6, %4 ], [ %12, %10 ]
%17 = tail call i32 @outbyte(i8 signext 10)
ret i32 %16
}