#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 *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  int x, y;
  int loops = 0;
  char s[100];
  char *p;
  printf("Enter number to count loops: ");
  scanf("%d", &x);
  y = x;
  sprintf(s, "%d", x);
  p = s;
  while (*p != '\0') {
    if (*p == '6')
      loops++;
    else if (*p == '8')
      loops += 2;
    else if (*p == '9')
      loops++;
    else if (*p == '0')
      loops++;
    p++;
  }
  printf("%d has %d loops\n", y, loops);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xea3(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1243 <main+0x113>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x36,%eax
jne    11bf <main+0x8f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122c <main+0xfc>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x38,%eax
jne    11e0 <main+0xb0>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0xf7>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jne    1201 <main+0xd1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1222 <main+0xf2>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    121d <main+0xed>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1222 <main+0xf2>
jmp    1227 <main+0xf7>
jmp    122c <main+0xfc>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    118b <main+0x5b>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0x10(%rsp),%rbx
lea    0xee2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef0(%rip),%r15
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1040 <scanf@plt>
mov    0xc(%rsp),%r14d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <sprintf@plt>
lea    0xe83(%rip),%rax
jmp    1187 <main+0x57>
nop
add    $0x1,%ebp
add    $0x1,%rbx
movzbl (%rbx),%ecx
lea    -0x30(%rcx),%edx
cmp    $0x9,%dl
ja     11a7 <main+0x77>
movzbl %dl,%ecx
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
add    $0x2,%ebp
add    $0x1,%rbx
jmp    1187 <main+0x57>
test   %cl,%cl
jne    1183 <main+0x53>
lea    0xe97(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"Enter number to count loops: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"%d has %d loops\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %21, %0
%10 = phi i32 [ 0, %0 ], [ %22, %21 ]
%11 = phi i8* [ %4, %0 ], [ %23, %21 ]
%12 = load i8, i8* %11
switch i8 %12, label %21 [
i8 0, label %24
i8 54, label %13
i8 56, label %15
i8 57, label %17
i8 48, label %19
]
13: ; preds = %9
%14 = add nsw i32 %10, 1
br label %21
15: ; preds = %9
%16 = add nsw i32 %10, 2
br label %21
17: ; preds = %9
%18 = add nsw i32 %10, 1
br label %21
19: ; preds = %9
%20 = add nsw i32 %10, 1
br label %21
21: ; preds = %9, %15, %19, %17, %13
%22 = phi i32 [ %14, %13 ], [ %16, %15 ], [ %18, %17 ], [ %20, %19 ], [ %10, %9 ]
%23 = getelementptr inbounds i8, i8* %11, i64 1
br label %9
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %10)
ret i32 0
}