#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 */
scalar_t__ strncmp(char const *, char *, int);
char *strrchr(char const *, char);
int gethead(const char *line, int prev) {
  if (prev < 0 && strncmp(line, "/*", 2) == 0)
    return 3;
  if (prev == 3) {
    const char *s = strrchr(line, '*');
    if (s && s[1] == '/')
      return 0;
    return 3;
  }
  if (strncmp(line, ";*", 2) == 0)
    return 1;
  if (strncmp(line, "@*", 2) == 0)
    return 2;
  return -1;
}


x86 assembly (clang, -O0):
<gethead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1164 <gethead+0x44>
mov    -0x10(%rbp),%rdi
lea    0xebc(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1164 <gethead+0x44>
movl   $0x3,-0x4(%rbp)
jmp    1211 <gethead+0xf1>
cmpl   $0x3,-0x14(%rbp)
jne    11b4 <gethead+0x94>
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a8 <gethead+0x88>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    11a8 <gethead+0x88>
movl   $0x0,-0x4(%rbp)
jmp    1211 <gethead+0xf1>
movl   $0x3,-0x4(%rbp)
jmp    1211 <gethead+0xf1>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11df <gethead+0xbf>
movl   $0x1,-0x4(%rbp)
jmp    1211 <gethead+0xf1>
mov    -0x10(%rbp),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120a <gethead+0xea>
movl   $0x2,-0x4(%rbp)
jmp    1211 <gethead+0xf1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethead>:
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
js     114c <gethead+0x2c>
cmp    $0x3,%esi
jne    1165 <gethead+0x45>
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     119c <gethead+0x7c>
mov    %rax,%rcx
xor    %eax,%eax
cmpb   $0x2f,0x1(%rcx)
jne    119c <gethead+0x7c>
pop    %rbx
ret
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     119c <gethead+0x7c>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a3 <gethead+0x83>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
neg    %rax
sbb    %eax,%eax
or     $0x2,%eax
pop    %rbx
ret
mov    $0x3,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"/*\00"
@.str.1 = [3 x i8] c";*\00"
@.str.2 = [3 x i8] c"@*\00"
define i32 @gethead(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 3, i32* %3
br label %41
14: ; preds = %9, %2
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i8* @strrchr(i8* %18, i8 signext 42)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %3
br label %41
29: ; preds = %22, %17
store i32 3, i32* %3
br label %41
30: ; preds = %14
%31 = load i8*, i8** %4
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 1, i32* %3
br label %41
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 2, i32* %3
br label %41
40: ; preds = %35
store i32 -1, i32* %3
br label %41
41: ; preds = %40, %39, %34, %29, %28, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"/*\00"
@.str.1 = [3 x i8] c";*\00"
@.str.2 = [3 x i8] c"@*\00"
define i32 @gethead(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %24, label %17
7: ; preds = %2
%8 = icmp eq i32 %1, 3
br i1 %8, label %9, label %17
9: ; preds = %7
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 42)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %24, label %16
16: ; preds = %12, %9
br label %24
17: ; preds = %4, %7
%18 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 2, i32 -1
br label %24
24: ; preds = %20, %17, %16, %12, %4
%25 = phi i32 [ 3, %4 ], [ 3, %16 ], [ 0, %12 ], [ 1, %17 ], [ %23, %20 ]
ret i32 %25
}