#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 power(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char **);
int strlen(char *);
void without_using_library_function() {
  char str[100];
  int number = 0;
  int digit, place = 0;
  int slen;
  int i;
  printf("Enter a number: ");
  scanf("%s", &str);
  slen = strlen(str);
  for (i = slen - 1; i > 0; i--) {
    digit = str[i] - '0';
    number += digit * power(place);
    place++;
  }
  if (str[0] == '-') {
    number *= -1;
  } else {
    digit = str[0] - '0';
    number += digit * power(place);
  }
  printf("Number: %d\n", number);
}


x86 assembly (clang, -O0):
<without_using_library_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jle    11ed <without_using_library_function+0xad>
movslq -0x84(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
sub    $0x30,%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x7c(%rbp),%edi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
imul   %ecx,%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
jmp    118f <without_using_library_function+0x4f>
movsbl -0x70(%rbp),%eax
cmp    $0x2d,%eax
jne    1206 <without_using_library_function+0xc6>
imul   $0xffffffff,-0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
jmp    1232 <without_using_library_function+0xf2>
movsbl -0x70(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x7c(%rbp),%edi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
imul   %ecx,%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<without_using_library_function>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xead(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x0,%r12d
cmp    $0x2,%eax
jl     11c7 <without_using_library_function+0x87>
mov    %eax,%r15d
mov    %eax,%ebx
add    $0xffffffff,%r15d
add    $0xffffffffffffffff,%rbx
xor    %r12d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
movsbl (%rsp,%rax,1),%r14d
add    $0xffffffd0,%r14d
mov    %ebp,%edi
call   1030 <power@plt>
imul   %r14d,%eax
add    %eax,%r12d
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
test   %ebx,%ebx
jne    11a0 <without_using_library_function+0x60>
mov    %r15d,%r14d
movsbl (%rsp),%ebx
cmp    $0x2d,%ebx
jne    11d5 <without_using_library_function+0x95>
neg    %r12d
jmp    11e6 <without_using_library_function+0xa6>
add    $0xffffffd0,%ebx
mov    %r14d,%edi
call   1030 <power@plt>
imul   %ebx,%eax
add    %eax,%r12d
lea    0xe27(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [12 x i8] c"Number: %d\0A\00"
define void @without_using_library_function() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [100 x i8]* %1 to i8**
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%6 = call i32 @strlen(i8* %2)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %26
8: ; preds = %0
%9 = zext i32 %6 to i64
%10 = add nsw i32 %6, -1
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %9, %8 ], [ %15, %11 ]
%13 = phi i32 [ 0, %8 ], [ %23, %11 ]
%14 = phi i32 [ 0, %8 ], [ %24, %11 ]
%15 = add nsw i64 %12, -1
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %19, -48
%21 = call i32 @power(i32 %14)
%22 = mul nsw i32 %20, %21
%23 = add nsw i32 %22, %13
%24 = add nuw nsw i32 %14, 1
%25 = icmp eq i32 %24, %10
br i1 %25, label %26, label %11
26: ; preds = %11, %0
%27 = phi i32 [ 0, %0 ], [ %10, %11 ]
%28 = phi i32 [ 0, %0 ], [ %23, %11 ]
%29 = load i8, i8* %2
%30 = icmp eq i8 %29, 45
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = sub nsw i32 0, %28
br label %39
33: ; preds = %26
%34 = sext i8 %29 to i32
%35 = add nsw i32 %34, -48
%36 = call i32 @power(i32 %27)
%37 = mul nsw i32 %36, %35
%38 = add nsw i32 %37, %28
br label %39
39: ; preds = %33, %31
%40 = phi i32 [ %32, %31 ], [ %38, %33 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %40)
ret void
}