#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__ strcmp(char const *, char *);
int strlen(char const *);
int gui_key_is_complete(const char *key) {
  int length;
  if (!key || !key[0])
    return 1;
  length = strlen(key);
  if (((length >= 1) && (strcmp(key + length - 1, "\x01") == 0)) ||
      ((length >= 2) && (strcmp(key + length - 2, "\x01[") == 0)) ||
      ((length >= 3) && (strcmp(key + length - 3, "\x01[[") == 0)))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<gui_key_is_complete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1144 <gui_key_is_complete+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1150 <gui_key_is_complete+0x30>
movl   $0x1,-0x4(%rbp)
jmp    11fc <gui_key_is_complete+0xdc>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     118b <gui_key_is_complete+0x6b>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe84(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <gui_key_is_complete+0xc9>
cmpl   $0x2,-0x14(%rbp)
jl     11ba <gui_key_is_complete+0x9a>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <gui_key_is_complete+0xc9>
cmpl   $0x3,-0x14(%rbp)
jl     11f5 <gui_key_is_complete+0xd5>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe2b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f5 <gui_key_is_complete+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    11fc <gui_key_is_complete+0xdc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_key_is_complete>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
test   %rdi,%rdi
je     11a7 <gui_key_is_complete+0x87>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11a7 <gui_key_is_complete+0x87>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a2 <gui_key_is_complete+0x82>
mov    %eax,%r14d
mov    %eax,%r15d
lea    (%rbx,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xea6(%rip),%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11a7 <gui_key_is_complete+0x87>
cmp    $0x2,%r14d
jb     11a2 <gui_key_is_complete+0x82>
add    %r15,%rbx
lea    -0x2(%rbx),%rdi
lea    0xe88(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a7 <gui_key_is_complete+0x87>
cmp    $0x3,%r14d
jb     11a2 <gui_key_is_complete+0x82>
add    $0xfffffffffffffffd,%rbx
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a7 <gui_key_is_complete+0x87>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\01\00"
@.str.1 = [3 x i8] c"\01[\00"
@.str.2 = [4 x i8] c"\01[[\00"
define i32 @gui_key_is_complete(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %9
%16 = icmp ugt i32 %7, 1
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %11, i64 -2
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = icmp ugt i32 %7, 2
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = getelementptr inbounds i8, i8* %11, i64 -3
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %6, %15, %23, %21
br label %28
28: ; preds = %9, %17, %23, %1, %3, %27
%29 = phi i32 [ 1, %27 ], [ 1, %3 ], [ 1, %1 ], [ 0, %23 ], [ 0, %17 ], [ 0, %9 ]
ret i32 %29
}