#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() {
  int suma = 0;
  char znakovi;
  printf("Unesite znakove: ");
  do {
    scanf("%d", &znakovi);
    if (znakovi >= 0 && znakovi <= 9)
      suma += znakovi;
    printf("Suma je: %d\n", suma);
  } while (znakovi != '.');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jl     1178 <main+0x58>
movsbl -0x9(%rbp),%eax
cmp    $0x9,%eax
jg     1178 <main+0x58>
movsbl -0x9(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x2e,%eax
jne    1144 <main+0x24>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xece(%rip),%r14
lea    0xf(%rsp),%r15
lea    0xec5(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
cmovae %r12d,%eax
movzbl %al,%eax
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmpb   $0x2e,0xf(%rsp)
jne    1160 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Unesite znakove: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Suma je: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %22, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp sle i32 %12, 9
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = load i32, i32* %2
%18 = add nsw i32 %17, %16
store i32 %18, i32* %2
br label %19
19: ; preds = %14, %10, %5
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 46
br i1 %25, label %5, label %26
26: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Unesite znakove: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Suma je: %d\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 0, %0 ], [ %10, %3 ]
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%6 = load i8, i8* %1
%7 = icmp ult i8 %6, 10
%8 = select i1 %7, i8 %6, i8 0
%9 = zext i8 %8 to i32
%10 = add nuw nsw i32 %4, %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i8, i8* %1
%13 = icmp eq i8 %12, 46
br i1 %13, label %14, label %3
14: ; preds = %3
ret i32 0
}