#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char str[10] = {0};
  int i, n;
  n = 0;
  printf("Enter str:");
  scanf("%s", str);
  printf("str : %s\n", str);
  for (i = 0; str[i] != '\0'; i++) {
    if (str[i] >= '0' && str[i] <= '9')
      n = (n * 10) + (str[i] - '0');
  }
  printf("integer %d\n", n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1050 <scanf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11eb <main+0xbb>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     11d8 <main+0xa8>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jg     11d8 <main+0xa8>
imul   $0xa,-0x18(%rbp),%eax
movslq -0x14(%rbp),%rcx
movsbl -0xe(%rbp,%rcx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <main+0xad>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x5d>
mov    -0x18(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xec2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <scanf@plt>
lea    0xeac(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%dl
test   %dl,%dl
je     11a1 <main+0x81>
lea    0x9(%rsp),%rax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movsbl %dl,%edx
lea    -0x30(%rdx),%esi
cmp    $0xa,%sil
lea    (%rcx,%rcx,4),%esi
lea    -0x30(%rdx,%rsi,2),%ebx
cmovae %ecx,%ebx
movzbl (%rax),%edx
add    $0x1,%rax
mov    %ebx,%ecx
test   %dl,%dl
jne    1180 <main+0x60>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Enter str:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"str : %s\0A\00"
@.str.3 = [12 x i8] c"integer %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [10 x i8]* %2 to i8*
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %9)
store i32 0, i32* %3
br label %11
11: ; preds = %43, %0
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %46
18: ; preds = %11
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 48
br i1 %24, label %25, label %42
25: ; preds = %18
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sle i32 %30, 57
br i1 %31, label %32, label %42
32: ; preds = %25
%33 = load i32, i32* %4
%34 = mul nsw i32 %33, 10
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 48
%41 = add nsw i32 %34, %40
store i32 %41, i32* %4
br label %42
42: ; preds = %32, %25, %18
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %11
46: ; preds = %11
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"Enter str:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"str : %s\0A\00"
@.str.3 = [12 x i8] c"integer %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %19, %8 ], [ 0, %0 ]
%10 = phi i8 [ %21, %8 ], [ %6, %0 ]
%11 = phi i32 [ %18, %8 ], [ 0, %0 ]
%12 = sext i8 %10 to i32
%13 = add i8 %10, -48
%14 = icmp ult i8 %13, 10
%15 = mul nsw i32 %11, 10
%16 = add i32 %15, -48
%17 = add i32 %16, %12
%18 = select i1 %14, i32 %17, i32 %11
%19 = add nuw nsw i64 %9, 1
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %8, %0
%24 = phi i32 [ 0, %0 ], [ %18, %8 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24)
ret i32 0
}