#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char KEY_ENTER;
char fgetc(int /*<<< orphan*/ *);
unsigned int get_num_from_cmdline(char cur_char, FILE *tty) {
  unsigned int i = cur_char - 48;
  while ((cur_char = fgetc(tty)) != KEY_ENTER) {
    if (cur_char == KEY_ENTER) {
      return i;
    } else if (cur_char >= 48 && cur_char <= 58) {
      i = i * 10 + cur_char - 48;
    } else {
      return 0;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<get_num_from_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e96(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11b3 <get_num_from_cmdline+0xa3>
movsbl -0x5(%rbp),%eax
mov    0x2e80(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    116e <get_num_from_cmdline+0x5e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <get_num_from_cmdline+0xa9>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     119d <get_num_from_cmdline+0x8d>
movsbl -0x5(%rbp),%eax
cmp    $0x3a,%eax
jg     119d <get_num_from_cmdline+0x8d>
imul   $0xa,-0x14(%rbp),%eax
movsbl -0x5(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <get_num_from_cmdline+0x99>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <get_num_from_cmdline+0xa9>
jmp    11ae <get_num_from_cmdline+0x9e>
jmp    112c <get_num_from_cmdline+0x1c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_from_cmdline>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
add    $0xffffffd0,%ebx
mov    %rsi,%rdi
call   1030 <fgetc@plt>
mov    0x2eac(%rip),%r15
cmp    (%r15),%al
je     1165 <get_num_from_cmdline+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
ja     1163 <get_num_from_cmdline+0x53>
movzbl %al,%eax
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
add    $0xffffffd0,%ebx
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%al
jne    1140 <get_num_from_cmdline+0x30>
jmp    1165 <get_num_from_cmdline+0x55>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@KEY_ENTER = global i8 0
define i32 @get_num_from_cmdline(i8 signext %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i32
store i8 %0, i8* %4
store i32* %1, i32** %5
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
%9 = sub nsw i32 %8, 48
store i32 %9, i32* %6
br label %10
10: ; preds = %42, %2
%11 = load i32*, i32** %5
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %4
%13 = sext i8 %12 to i32
%14 = load i8, i8* @KEY_ENTER
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %43
17: ; preds = %10
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* @KEY_ENTER
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %45
25: ; preds = %17
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = icmp sle i32 %31, 58
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i32, i32* %6
%35 = mul i32 %34, 10
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = add i32 %35, %37
%39 = sub i32 %38, 48
store i32 %39, i32* %6
br label %41
40: ; preds = %29, %25
store i32 0, i32* %3
br label %45
41: ; preds = %33
br label %42
42: ; preds = %41
br label %10
43: ; preds = %10
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %40, %23
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@KEY_ENTER = global i8 0
define i32 @get_num_from_cmdline(i8 signext %0, i32* nocapture %1) {
%3 = sext i8 %0 to i32
%4 = add nsw i32 %3, -48
%5 = tail call signext i8 @fgetc(i32* %1)
%6 = load i8, i8* @KEY_ENTER
%7 = icmp eq i8 %5, %6
br i1 %7, label %21, label %8
8: ; preds = %2, %13
%9 = phi i8 [ %18, %13 ], [ %5, %2 ]
%10 = phi i32 [ %17, %13 ], [ %4, %2 ]
%11 = add i8 %9, -48
%12 = icmp ult i8 %11, 11
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = zext i8 %9 to i32
%15 = mul i32 %10, 10
%16 = add i32 %15, %14
%17 = add i32 %16, -48
%18 = tail call signext i8 @fgetc(i32* %1)
%19 = load i8, i8* @KEY_ENTER
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %8
21: ; preds = %8, %13, %2
%22 = phi i32 [ %4, %2 ], [ %17, %13 ], [ 0, %8 ]
ret i32 %22
}