#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ blankline(char *, char **);
int getc(int /*<<< orphan*/ *);
void decomment_sh(const char *fname, FILE *in) {
  register int c, c1;
  char outbuf[4 * 1024];
  char *op = outbuf;
  enum {
    NORMAL,
    SH_COMMENT,
    DOUBLEQUOTESTRING,
    SINGLEQUOTESTRING
  } state = NORMAL;
  while ((c = getc(in)) != EOF) {
    switch (state) {
    case NORMAL:
      switch (c) {
      case '\'':
        state = SINGLEQUOTESTRING;
        *op++ = c;
        break;
      case '"':
        state = DOUBLEQUOTESTRING;
        *op++ = c;
        break;
      case '#':
        state = SH_COMMENT;
        break;
      case '\\':
        *op++ = c;
        c1 = getc(in);
        *op++ = c1;
        break;
      default:
        *op++ = c;
        break;
      }
      break;
    case SH_COMMENT:
      if (c == '\n') {
        state = NORMAL;
      }
      break;
    case DOUBLEQUOTESTRING:
      *op++ = c;
      switch (c) {
      case '"':
        state = NORMAL;
        break;
      case '\\':
        c1 = getc(in);
        *op++ = c1;
        break;
      }
      break;
    case SINGLEQUOTESTRING:
      *op++ = c;
      switch (c) {
      case '\'':
        state = NORMAL;
        break;
      case '\\':
        getc(in);
        break;
      }
      break;
    }
    if (op > outbuf && op[-1] == '\n') {
      blankline(outbuf, &op);
    }
  }
}


x86 assembly (clang, -O0):
<decomment_sh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
movl   $0x0,-0x102c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
je     13f5 <decomment_sh+0x2d5>
mov    -0x102c(%rbp),%eax
mov    %rax,-0x1038(%rbp)
sub    $0x3,%rax
ja     13b2 <decomment_sh+0x292>
mov    -0x1038(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
mov    %eax,-0x103c(%rbp)
sub    $0x22,%eax
je     1212 <decomment_sh+0xf2>
jmp    11ab <decomment_sh+0x8b>
mov    -0x103c(%rbp),%eax
sub    $0x23,%eax
je     123d <decomment_sh+0x11d>
jmp    11bf <decomment_sh+0x9f>
mov    -0x103c(%rbp),%eax
sub    $0x27,%eax
je     11e7 <decomment_sh+0xc7>
jmp    11d3 <decomment_sh+0xb3>
mov    -0x103c(%rbp),%eax
sub    $0x5c,%eax
je     124c <decomment_sh+0x12c>
jmp    1295 <decomment_sh+0x175>
movl   $0x3,-0x102c(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
jmp    12b1 <decomment_sh+0x191>
movl   $0x2,-0x102c(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
jmp    12b1 <decomment_sh+0x191>
movl   $0x1,-0x102c(%rbp)
jmp    12b1 <decomment_sh+0x191>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
jmp    12b1 <decomment_sh+0x191>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
jmp    13b2 <decomment_sh+0x292>
cmpl   $0xa,-0x14(%rbp)
jne    12ca <decomment_sh+0x1aa>
movl   $0x0,-0x102c(%rbp)
jmp    13b2 <decomment_sh+0x292>
mov    -0x14(%rbp),%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1040(%rbp)
sub    $0x22,%eax
je     1314 <decomment_sh+0x1f4>
jmp    1300 <decomment_sh+0x1e0>
mov    -0x1040(%rbp),%eax
sub    $0x5c,%eax
je     1323 <decomment_sh+0x203>
jmp    134b <decomment_sh+0x22b>
movl   $0x0,-0x102c(%rbp)
jmp    134b <decomment_sh+0x22b>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
jmp    13b2 <decomment_sh+0x292>
mov    -0x14(%rbp),%cl
mov    -0x1028(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1028(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1044(%rbp)
sub    $0x27,%eax
je     1395 <decomment_sh+0x275>
jmp    1381 <decomment_sh+0x261>
mov    -0x1044(%rbp),%eax
sub    $0x5c,%eax
je     13a4 <decomment_sh+0x284>
jmp    13ad <decomment_sh+0x28d>
movl   $0x0,-0x102c(%rbp)
jmp    13ad <decomment_sh+0x28d>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
jmp    13b2 <decomment_sh+0x292>
mov    -0x1028(%rbp),%rax
lea    -0x1020(%rbp),%rcx
cmp    %rcx,%rax
jbe    13f0 <decomment_sh+0x2d0>
mov    -0x1028(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    13f0 <decomment_sh+0x2d0>
lea    -0x1020(%rbp),%rdi
lea    -0x1028(%rbp),%rsi
call   1030 <blankline@plt>
jmp    114b <decomment_sh+0x2b>
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decomment_sh>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,0x8(%rsp)
mov    %rsi,%rdi
call   1040 <getc@plt>
mov    0x2e9b(%rip),%r12
cmp    (%r12),%eax
jne    1165 <decomment_sh+0x45>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
lea    0xe8d(%rip),%r13
jmp    118e <decomment_sh+0x6e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    (%r12),%eax
je     1153 <decomment_sh+0x33>
cmp    $0x3,%ebp
ja     12c1 <decomment_sh+0x1a1>
mov    %ebp,%ecx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
cmp    $0x26,%eax
jg     1238 <decomment_sh+0x118>
cmp    $0x22,%eax
je     127e <decomment_sh+0x15e>
mov    $0x1,%ebp
cmp    $0x23,%eax
je     12c1 <decomment_sh+0x1a1>
jmp    12af <decomment_sh+0x18f>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cmp    $0xa,%eax
setne  %bpl
jmp    12c1 <decomment_sh+0x1a1>
xchg   %ax,%ax
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    %al,(%rcx)
mov    $0x2,%ebp
cmp    $0x5c,%eax
je     125a <decomment_sh+0x13a>
cmp    $0x22,%eax
je     12bf <decomment_sh+0x19f>
jmp    12c1 <decomment_sh+0x1a1>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    %al,(%rcx)
mov    $0x3,%ebp
cmp    $0x5c,%eax
je     1274 <decomment_sh+0x154>
cmp    $0x27,%eax
je     12bf <decomment_sh+0x19f>
jmp    12c1 <decomment_sh+0x1a1>
cmp    $0x5c,%eax
je     1296 <decomment_sh+0x176>
cmp    $0x27,%eax
jne    12af <decomment_sh+0x18f>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
movb   $0x27,(%rax)
mov    $0x3,%ebp
jmp    12c1 <decomment_sh+0x1a1>
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    %al,(%rcx)
jmp    12c1 <decomment_sh+0x1a1>
mov    %rbx,%rdi
call   1040 <getc@plt>
jmp    12c1 <decomment_sh+0x1a1>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
movb   $0x22,(%rax)
mov    $0x2,%ebp
jmp    12c1 <decomment_sh+0x1a1>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
movb   $0x5c,(%rax)
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    %al,(%rcx)
xor    %ebp,%ebp
mov    0x8(%rsp),%rax
cmp    %r14,%rax
jbe    1180 <decomment_sh+0x60>
cmpb   $0xa,-0x1(%rax)
jne    1180 <decomment_sh+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <blankline@plt>
jmp    1180 <decomment_sh+0x60>

LLVM IR (-O0):
@EOF = global i32 0
define void @decomment_sh(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
store i8* %10, i8** %8
store i32 0, i32* %9
br label %11
11: ; preds = %92, %2
%12 = load i32*, i32** %4
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %5
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %93
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %79 [
i32 0, label %18
i32 1, label %48
i32 2, label %53
i32 3, label %68
]
18: ; preds = %16
%19 = load i32, i32* %5
switch i32 %19, label %42 [
i32 39, label %20
i32 34, label %25
i32 35, label %30
i32 92, label %31
]
20: ; preds = %18
store i32 3, i32* %9
%21 = load i32, i32* %5
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %8
store i8 %22, i8* %23
br label %47
25: ; preds = %18
store i32 2, i32* %9
%26 = load i32, i32* %5
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %8
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %8
store i8 %27, i8* %28
br label %47
30: ; preds = %18
store i32 1, i32* %9
br label %47
31: ; preds = %18
%32 = load i32, i32* %5
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %8
store i8 %33, i8* %34
%36 = load i32*, i32** %4
%37 = call i32 @getc(i32* %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %8
store i8 %39, i8* %40
br label %47
42: ; preds = %18
%43 = load i32, i32* %5
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %8
store i8 %44, i8* %45
br label %47
47: ; preds = %42, %31, %30, %25, %20
br label %79
48: ; preds = %16
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 10
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 0, i32* %9
br label %52
52: ; preds = %51, %48
br label %79
53: ; preds = %16
%54 = load i32, i32* %5
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %8
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %8
store i8 %55, i8* %56
%58 = load i32, i32* %5
switch i32 %58, label %67 [
i32 34, label %59
i32 92, label %60
]
59: ; preds = %53
store i32 0, i32* %9
br label %67
60: ; preds = %53
%61 = load i32*, i32** %4
%62 = call i32 @getc(i32* %61)
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %8
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %8
store i8 %64, i8* %65
br label %67
67: ; preds = %53, %60, %59
br label %79
68: ; preds = %16
%69 = load i32, i32* %5
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %8
store i8 %70, i8* %71
%73 = load i32, i32* %5
switch i32 %73, label %78 [
i32 39, label %74
i32 92, label %75
]
74: ; preds = %68
store i32 0, i32* %9
br label %78
75: ; preds = %68
%76 = load i32*, i32** %4
%77 = call i32 @getc(i32* %76)
br label %78
78: ; preds = %68, %75, %74
br label %79
79: ; preds = %16, %78, %67, %52, %47
%80 = load i8*, i8** %8
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%82 = icmp ugt i8* %80, %81
br i1 %82, label %83, label %92
83: ; preds = %79
%84 = load i8*, i8** %8
%85 = getelementptr inbounds i8, i8* %84, i64 -1
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp eq i32 %87, 10
br i1 %88, label %89, label %92
89: ; preds = %83
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%91 = call i32 @blankline(i8* %90, i8** %8)
br label %92
92: ; preds = %89, %83, %79
br label %11
93: ; preds = %11
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @decomment_sh(i8* nocapture readnone %0, i32* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
store i8* %5, i8** %4
%7 = call i32 @getc(i32* %1)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %65, label %10
10: ; preds = %2, %61
%11 = phi i32 [ %62, %61 ], [ %7, %2 ]
%12 = phi i32 [ %52, %61 ], [ 0, %2 ]
switch i32 %12, label %51 [
i32 0, label %13
i32 1, label %31
i32 2, label %34
i32 3, label %44
]
13: ; preds = %10
switch i32 %11, label %27 [
i32 39, label %14
i32 34, label %17
i32 35, label %51
i32 92, label %20
]
14: ; preds = %13
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %4
store i8 39, i8* %15
br label %51
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %4
store i8 34, i8* %18
br label %51
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %4
store i8 92, i8* %21
%23 = call i32 @getc(i32* %1)
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %4
store i8 %24, i8* %25
br label %51
27: ; preds = %13
%28 = trunc i32 %11 to i8
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %4
store i8 %28, i8* %29
br label %51
31: ; preds = %10
%32 = icmp ne i32 %11, 10
%33 = zext i1 %32 to i32
br label %51
34: ; preds = %10
%35 = trunc i32 %11 to i8
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %4
store i8 %35, i8* %36
switch i32 %11, label %51 [
i32 34, label %38
i32 92, label %39
]
38: ; preds = %34
br label %51
39: ; preds = %34
%40 = call i32 @getc(i32* %1)
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %4
store i8 %41, i8* %42
br label %51
44: ; preds = %10
%45 = trunc i32 %11 to i8
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %4
store i8 %45, i8* %46
switch i32 %11, label %51 [
i32 39, label %48
i32 92, label %49
]
48: ; preds = %44
br label %51
49: ; preds = %44
%50 = call i32 @getc(i32* %1)
br label %51
51: ; preds = %31, %13, %48, %49, %44, %38, %39, %34, %14, %17, %20, %27, %10
%52 = phi i32 [ %12, %10 ], [ 3, %44 ], [ 3, %49 ], [ 0, %48 ], [ 2, %34 ], [ 2, %39 ], [ 0, %38 ], [ 0, %27 ], [ 0, %20 ], [ 2, %17 ], [ 3, %14 ], [ 1, %13 ], [ %33, %31 ]
%53 = load i8*, i8** %4
%54 = icmp ugt i8* %53, %5
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = getelementptr inbounds i8, i8* %53, i64 -1
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 10
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @blankline(i8* %5, i8** %4)
br label %61
61: ; preds = %59, %55, %51
%62 = call i32 @getc(i32* %1)
%63 = load i32, i32* @EOF
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %10
65: ; preds = %61, %2
ret void
}