#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 c;
  int n = 0;
  printf("Please enter something ends with '#'\n");
  while ((c = getchar()) != '#') {
    switch (c) {
    case '.':
      putchar('!');
      n++;
      break;
    case '!':
      putchar('!');
      putchar('!');
      n++;
      break;
    default:
      putchar(c);
    }
  }
  putchar('\n');
  printf("You've made %d substitutions!\n", n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0x23,%eax
je     11d8 <main+0xa8>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x21,%eax
je     11a8 <main+0x78>
jmp    117f <main+0x4f>
mov    -0x10(%rbp),%eax
sub    $0x2e,%eax
jne    11ca <main+0x9a>
jmp    1190 <main+0x60>
mov    $0x21,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <main+0xa3>
mov    $0x21,%edi
call   1030 <putchar@plt>
mov    $0x21,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d3 <main+0xa3>
movsbl -0x5(%rbp),%edi
call   1030 <putchar@plt>
jmp    1154 <main+0x24>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x23,%al
jne    1178 <main+0x38>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %ebx,%ebx
jmp    11a2 <main+0x62>
nopl   0x0(%rax)
mov    $0x21,%edi
call   1030 <putchar@plt>
mov    $0x21,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x23,%al
je     115a <main+0x1a>
movsbl %al,%edi
cmp    $0x21,%edi
je     1180 <main+0x40>
cmp    $0x2e,%edi
je     118a <main+0x4a>
call   1030 <putchar@plt>
jmp    1197 <main+0x57>

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

LLVM IR (-O2):
@.str.1 = [31 x i8] c"You've made %d substitutions!\0A\00"
@str = [37 x i8] c"Please enter something ends with '#'\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 35
br i1 %3, label %21, label %4
4: ; preds = %0, %17
%5 = phi i8 [ %19, %17 ], [ %2, %0 ]
%6 = phi i32 [ %18, %17 ], [ 0, %0 ]
%7 = sext i8 %5 to i32
switch i32 %7, label %15 [
i32 46, label %8
i32 33, label %11
]
8: ; preds = %4
%9 = tail call i32 @putchar(i8 signext 33)
%10 = add nsw i32 %6, 1
br label %17
11: ; preds = %4
%12 = tail call i32 @putchar(i8 signext 33)
%13 = tail call i32 @putchar(i8 signext 33)
%14 = add nsw i32 %6, 1
br label %17
15: ; preds = %4
%16 = tail call i32 @putchar(i8 signext %5)
br label %17
17: ; preds = %15, %11, %8
%18 = phi i32 [ %6, %15 ], [ %14, %11 ], [ %10, %8 ]
%19 = tail call signext i8 (...) @getchar()
%20 = icmp eq i8 %19, 35
br i1 %20, label %21, label %4
21: ; preds = %17, %0
%22 = phi i32 [ 0, %0 ], [ %18, %17 ]
%23 = tail call i32 @putchar(i8 signext 10)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 0
}