#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(void) {
  char ch;
  int i = 0;
  while ((ch = getchar()) != '#') {
    if (ch == '.') {
      i++;
      putchar('!');
    } else if (ch == '!') {
      i++;
      printf("!!");
    } else
      putchar(ch);
  }
  printf("\n%d replaces.\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0x23,%eax
je     11bd <main+0x8d>
movsbl -0x5(%rbp),%eax
cmp    $0x2e,%eax
jne    1181 <main+0x51>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x21,%edi
call   1030 <putchar@plt>
jmp    11b8 <main+0x88>
movsbl -0x5(%rbp),%eax
cmp    $0x21,%eax
jne    11aa <main+0x7a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b3 <main+0x83>
movsbl -0x5(%rbp),%edi
call   1030 <putchar@plt>
jmp    11b8 <main+0x88>
jmp    1146 <main+0x16>
mov    -0xc(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x21,%al
je     115d <main+0x2d>
cmp    $0x23,%al
je     117b <main+0x4b>
cmp    $0x2e,%al
je     116c <main+0x3c>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1140 <main+0x10>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
jmp    1140 <main+0x10>
mov    $0x21,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
jmp    1140 <main+0x10>
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"!!\00"
@.str.1 = [15 x i8] c"\0A%d replaces.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %28, %0
%5 = call signext i8 (...) @getchar()
store i8 %5, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 35
br i1 %7, label %8, label %29
8: ; preds = %4
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 46
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = call i32 @putchar(i8 signext 33)
br label %28
16: ; preds = %8
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 33
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %27
24: ; preds = %16
%25 = load i8, i8* %2
%26 = call i32 @putchar(i8 signext %25)
br label %27
27: ; preds = %24, %20
br label %28
28: ; preds = %27, %12
br label %4
29: ; preds = %4
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"!!\00"
@.str.1 = [15 x i8] c"\0A%d replaces.\0A\00"
define i32 @main() {
br label %1
1: ; preds = %7, %0
%2 = phi i32 [ 0, %0 ], [ %8, %7 ]
br label %3
3: ; preds = %1, %11
%4 = tail call signext i8 (...) @getchar()
switch i8 %4, label %11 [
i8 35, label %13
i8 46, label %5
i8 33, label %9
]
5: ; preds = %3
%6 = tail call i32 @putchar(i8 signext 33)
br label %7
7: ; preds = %5, %9
%8 = add nuw nsw i32 %2, 1
br label %1
9: ; preds = %3
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
11: ; preds = %3
%12 = tail call i32 @putchar(i8 signext %4)
br label %3
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %2)
ret i32 0
}