#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*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
int /*<<< orphan*/ exit_with(char *, int);
int /*<<< orphan*/ *malloc(int);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int nickname_valid(char *nickname) {
  char regex[] = "^[A-z0-9 ]+$";
  static int initialized = 0;
  static regex_t *regex_comp;
  if (!initialized) {
    if (!(regex_comp = malloc(sizeof(regex_t)))) {
      exit_with("malloc error", 1);
    }
    if (regcomp(regex_comp, regex, REG_EXTENDED | REG_NOSUB)) {
      exit_with("regex compilation error", 0);
    }
    initialized = 1;
  }
  return regexec(regex_comp, nickname, 0, NULL, 0) ? 0 : 1;
}


x86 assembly (clang, -O0):
<nickname_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x15(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xea6(%rip),%al
mov    %al,-0x9(%rbp)
cmpl   $0x0,0x2ed8(%rip)
jne    11e6 <nickname_valid+0xa6>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,0x2ec9(%rip)
cmp    $0x0,%rax
jne    11a2 <nickname_valid+0x62>
lea    0xe75(%rip),%rdi
mov    $0x1,%esi
call   1060 <exit_with@plt>
mov    0x2ea7(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    0x2e23(%rip),%rax
or     (%rax),%edx
call   1030 <regcomp@plt>
cmp    $0x0,%rax
je     11dc <nickname_valid+0x9c>
lea    0xe45(%rip),%rdi
xor    %esi,%esi
call   1060 <exit_with@plt>
movl   $0x1,0x2e62(%rip)
mov    0x2e63(%rip),%rdi
mov    -0x8(%rbp),%rsi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1050 <regexec@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nickname_valid>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movabs $0x242b5d20392d30,%rax
mov    %rax,0x5(%rsp)
movabs $0x392d307a2d415b5e,%rax
30 2d 39
mov    %rax,(%rsp)
cmpb   $0x0,0x2edc(%rip)
jne    11d3 <nickname_valid+0x93>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,0x2ed1(%rip)
test   %rax,%rax
jne    119c <nickname_valid+0x5c>
lea    0xe82(%rip),%rdi
mov    $0x1,%esi
call   1060 <exit_with@plt>
mov    0x2eb4(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    0x2e36(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <regcomp@plt>
test   %rax,%rax
je     11cc <nickname_valid+0x8c>
lea    0xe55(%rip),%rdi
xor    %esi,%esi
call   1060 <exit_with@plt>
movb   $0x1,0x2e75(%rip)
mov    0x2e76(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.nickname_valid.regex = [13 x i8] c"^[A-z0-9 ]+$\00"
@nickname_valid.initialized = internal global i32 0
@nickname_valid.regex_comp = internal global i32* null
@.str = [13 x i8] c"malloc error\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str.1 = [24 x i8] c"regex compilation error\00"
define i32 @nickname_valid(i8* %0) {
%2 = alloca i8*
%3 = alloca [13 x i8]
store i8* %0, i8** %2
%4 = bitcast [13 x i8]* %3 to i8*
%5 = load i32, i32* @nickname_valid.initialized
%6 = icmp ne i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %1
%8 = call i32* @malloc(i32 4)
store i32* %8, i32** @nickname_valid.regex_comp
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
br label %12
12: ; preds = %10, %7
%13 = load i32*, i32** @nickname_valid.regex_comp
%14 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @REG_EXTENDED
%16 = load i32, i32* @REG_NOSUB
%17 = or i32 %15, %16
%18 = call i64 @regcomp(i32* %13, i8* %14, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @exit_with(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %22
22: ; preds = %20, %12
store i32 1, i32* @nickname_valid.initialized
br label %23
23: ; preds = %22, %1
%24 = load i32*, i32** @nickname_valid.regex_comp
%25 = load i8*, i8** %2
%26 = call i64 @regexec(i32* %24, i8* %25, i32 0, i32* null, i32 0)
%27 = icmp ne i64 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 1
ret i32 %29
}

LLVM IR (-O2):
@__const.nickname_valid.regex = [13 x i8] c"^[A-z0-9 ]+$\00"
@nickname_valid.initialized = internal unnamed_addr global i1 false
@nickname_valid.regex_comp = internal unnamed_addr global i32* null
@.str = [13 x i8] c"malloc error\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str.1 = [24 x i8] c"regex compilation error\00"
define i32 @nickname_valid(i8* %0) {
%2 = alloca [13 x i8]
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%4 = load i1, i1* @nickname_valid.initialized
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = tail call i32* @malloc(i32 4)
store i32* %6, i32** @nickname_valid.regex_comp
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = load i32*, i32** @nickname_valid.regex_comp
br label %11
11: ; preds = %8, %5
%12 = phi i32* [ %10, %8 ], [ %6, %5 ]
%13 = load i32, i32* @REG_EXTENDED
%14 = load i32, i32* @REG_NOSUB
%15 = or i32 %14, %13
%16 = call i64 @regcomp(i32* %12, i8* %3, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = call i32 @exit_with(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %20
20: ; preds = %18, %11
store i1 true, i1* @nickname_valid.initialized
br label %21
21: ; preds = %20, %1
%22 = load i32*, i32** @nickname_valid.regex_comp
%23 = call i64 @regexec(i32* %22, i8* %0, i32 0, i32* null, i32 0)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
ret i32 %25
}