#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 EOF;
int getchar();
int /*<<< orphan*/ putchar(int);
int main(int argc, char *argv[]) {
  int state = 0;
  int c;
  while ((c = getchar()) != EOF) {
    switch (state) {
    case 0:
      if (c == '(')
        state = 1;
      else
        putchar(c);
      break;
    case 1:
      if (c == '*') {
        state = 2;
      } else {
        putchar('(');
        putchar(c);
        state = 0;
      }
      break;
    case 2:
      if (c == '*')
        state = 3;
      break;
    case 3:
      if (c == ')')
        state = 0;
      else
        state = 2;
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%eax
je     120f <main+0xef>
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     120a <main+0xea>
mov    -0x20(%rbp),%rax
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x28,-0x18(%rbp)
jne    1191 <main+0x71>
movl   $0x1,-0x14(%rbp)
jmp    1199 <main+0x79>
mov    -0x18(%rbp),%edi
call   1030 <putchar@plt>
jmp    120a <main+0xea>
cmpl   $0x2a,-0x18(%rbp)
jne    11b4 <main+0x94>
movl   $0x2,-0x14(%rbp)
jmp    11cd <main+0xad>
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x0,-0x14(%rbp)
jmp    120a <main+0xea>
cmpl   $0x2a,-0x18(%rbp)
jne    11e3 <main+0xc3>
movl   $0x3,-0x14(%rbp)
jmp    120a <main+0xea>
cmpl   $0x29,-0x18(%rbp)
jne    11fe <main+0xde>
movl   $0x0,-0x14(%rbp)
jmp    1205 <main+0xe5>
movl   $0x2,-0x14(%rbp)
jmp    120a <main+0xea>
jmp    113d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb3(%rip),%r14
cmp    (%r14),%eax
jne    1147 <main+0x27>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xeb0(%rip),%r15
xor    %ebp,%ebp
jmp    117e <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
cmp    $0x29,%ebx
setne  %bpl
add    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
je     113a <main+0x1a>
cmp    $0x3,%ebp
ja     1170 <main+0x50>
mov    %ebp,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x1,%ebp
cmp    $0x28,%ebx
je     1170 <main+0x50>
jmp    11b4 <main+0x94>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%ebp
cmp    $0x2a,%ebx
je     1170 <main+0x50>
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1170 <main+0x50>
nop
xor    %ebp,%ebp
cmp    $0x2a,%ebx
sete   %bpl
or     $0x2,%ebp
jmp    1170 <main+0x50>

LLVM IR (-O0):
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %42, %2
%9 = call i32 (...) @getchar()
store i32 %9, i32* %7
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %43
12: ; preds = %8
%13 = load i32, i32* %6
switch i32 %13, label %42 [
i32 0, label %14
i32 1, label %22
i32 2, label %31
i32 3, label %36
]
14: ; preds = %12
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 40
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %6
br label %21
18: ; preds = %14
%19 = load i32, i32* %7
%20 = call i32 @putchar(i32 %19)
br label %21
21: ; preds = %18, %17
br label %42
22: ; preds = %12
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 42
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 2, i32* %6
br label %30
26: ; preds = %22
%27 = call i32 @putchar(i32 40)
%28 = load i32, i32* %7
%29 = call i32 @putchar(i32 %28)
store i32 0, i32* %6
br label %30
30: ; preds = %26, %25
br label %42
31: ; preds = %12
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 42
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 3, i32* %6
br label %35
35: ; preds = %34, %31
br label %42
36: ; preds = %12
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 41
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 0, i32* %6
br label %41
40: ; preds = %36
store i32 2, i32* %6
br label %41
41: ; preds = %40, %39
br label %42
42: ; preds = %12, %41, %35, %30, %21
br label %8
43: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %29, label %6
6: ; preds = %2, %24
%7 = phi i32 [ %26, %24 ], [ %3, %2 ]
%8 = phi i32 [ %25, %24 ], [ 0, %2 ]
switch i32 %8, label %24 [
i32 0, label %9
i32 1, label %13
i32 2, label %18
i32 3, label %21
]
9: ; preds = %6
%10 = icmp eq i32 %7, 40
br i1 %10, label %24, label %11
11: ; preds = %9
%12 = tail call i32 @putchar(i32 %7)
br label %24
13: ; preds = %6
%14 = icmp eq i32 %7, 42
br i1 %14, label %24, label %15
15: ; preds = %13
%16 = tail call i32 @putchar(i32 40)
%17 = tail call i32 @putchar(i32 %7)
br label %24
18: ; preds = %6
%19 = icmp eq i32 %7, 42
%20 = select i1 %19, i32 3, i32 2
br label %24
21: ; preds = %6
%22 = icmp eq i32 %7, 41
%23 = select i1 %22, i32 0, i32 2
br label %24
24: ; preds = %18, %21, %13, %9, %15, %11, %6
%25 = phi i32 [ %8, %6 ], [ 0, %15 ], [ 0, %11 ], [ 1, %9 ], [ 2, %13 ], [ %20, %18 ], [ %23, %21 ]
%26 = tail call i32 (...) @getchar()
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %6
29: ; preds = %24, %2
ret i32 0
}