#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 /*<<< orphan*/ goodq(char const);
int whatch(char const);
int goodgbid(const char *userid) {
  int q = 0;
  const char *s;
  for (s = userid; *s != '\0'; s++) {
    switch (whatch(*s)) {
    case 0:
      return 0;
    case 1:
      if (q)
        return 0;
      break;
    case 2:
      if (!q && !goodq(*s))
        return 0;
      q = !q;
      break;
    }
  }
  if (q)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<goodgbid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1204 <goodgbid+0xe4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <whatch@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
test   %eax,%eax
je     118b <goodgbid+0x6b>
jmp    1169 <goodgbid+0x49>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     1197 <goodgbid+0x77>
jmp    117a <goodgbid+0x5a>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     11b2 <goodgbid+0x92>
jmp    11ee <goodgbid+0xce>
movl   $0x0,-0x4(%rbp)
jmp    1221 <goodgbid+0x101>
cmpl   $0x0,-0x14(%rbp)
je     11ad <goodgbid+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    1221 <goodgbid+0x101>
jmp    11ee <goodgbid+0xce>
cmpl   $0x0,-0x14(%rbp)
jne    11dd <goodgbid+0xbd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <goodq@plt>
cmp    $0x0,%eax
jne    11dd <goodgbid+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    1221 <goodgbid+0x101>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    11f3 <goodgbid+0xd3>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <goodgbid+0x1b>
cmpl   $0x0,-0x14(%rbp)
je     121a <goodgbid+0xfa>
movl   $0x0,-0x4(%rbp)
jmp    1221 <goodgbid+0x101>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goodgbid>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     118c <goodgbid+0x6c>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
jmp    1156 <goodgbid+0x36>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
test   %ebp,%ebp
mov    $0x0,%ebp
jne    1195 <goodgbid+0x75>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118e <goodgbid+0x6e>
movsbl %al,%edi
call   1030 <whatch@plt>
cmp    $0x1,%eax
je     1140 <goodgbid+0x20>
cmp    $0x2,%eax
je     1170 <goodgbid+0x50>
test   %eax,%eax
jne    114b <goodgbid+0x2b>
jmp    1195 <goodgbid+0x75>
xchg   %ax,%ax
test   %ebp,%ebp
jne    1181 <goodgbid+0x61>
movsbl -0x1(%rbx),%edi
call   1040 <goodq@plt>
test   %eax,%eax
je     119c <goodgbid+0x7c>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
mov    %eax,%ebp
jmp    114b <goodgbid+0x2b>
xor    %ebp,%ebp
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
jmp    1195 <goodgbid+0x75>

LLVM IR (-O0):
define i32 @goodgbid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %37, %1
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %40
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = call i32 @whatch(i8 signext %14)
switch i32 %15, label %36 [
i32 0, label %16
i32 1, label %17
i32 2, label %22
]
16: ; preds = %12
store i32 0, i32* %2
br label %45
17: ; preds = %12
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %2
br label %45
21: ; preds = %17
br label %36
22: ; preds = %12
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = call i32 @goodq(i8 signext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store i32 0, i32* %2
br label %45
31: ; preds = %25, %22
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
store i32 %35, i32* %4
br label %36
36: ; preds = %12, %31, %21
br label %37
37: ; preds = %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
br label %7
40: ; preds = %7
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %2
br label %45
44: ; preds = %40
store i32 1, i32* %2
br label %45
45: ; preds = %44, %43, %30, %20, %16
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
define i32 @goodgbid(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %24, label %4
4: ; preds = %1, %19
%5 = phi i8 [ %22, %19 ], [ %2, %1 ]
%6 = phi i8* [ %21, %19 ], [ %0, %1 ]
%7 = phi i32 [ %20, %19 ], [ 0, %1 ]
%8 = tail call i32 @whatch(i8 signext %5)
switch i32 %8, label %19 [
i32 0, label %28
i32 1, label %9
i32 2, label %11
]
9: ; preds = %4
%10 = icmp eq i32 %7, 0
br i1 %10, label %19, label %28
11: ; preds = %4
%12 = icmp eq i32 %7, 0
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = load i8, i8* %6
%15 = tail call i32 @goodq(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %13, %11
%18 = zext i1 %12 to i32
br label %19
19: ; preds = %17, %4, %9
%20 = phi i32 [ %7, %4 ], [ %18, %17 ], [ 0, %9 ]
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %4
24: ; preds = %19, %1
%25 = phi i32 [ 0, %1 ], [ %20, %19 ]
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %13, %9, %4, %24
%29 = phi i32 [ %27, %24 ], [ 0, %13 ], [ 0, %9 ], [ %8, %4 ]
ret i32 %29
}