#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 */
struct user {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ chatdat_valid_username(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ get_user(char const *, struct user *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strstr(char *, char *);
scalar_t__ yes_no();
void chatdat_gen_add_user(struct user *chatdat_users) {
  int good_name = 1;
  char uname[27];
prompt_uname:
  printf("Enter name of new user (; to exit): ");
  fgets(uname, 27, stdin);
  if (strstr(uname, ";"))
    return;
  if (!chatdat_valid_username(uname)) {
    printf("Invalid username. Please omit whitespace and special characters "
           "(spaces, tabs, ;, etc.).\n");
    good_name = 0;
  } else if (get_user((const char *)uname, chatdat_users)) {
    printf("The designated user already exists.\n");
    good_name = 0;
  }
  if (!good_name) {
    printf("Would you like to try a different name? (y/n) ");
    if (yes_no())
      goto prompt_uname;
    else
      return;
  }
}


x86 assembly (clang, -O0):
<chatdat_gen_add_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    $0x1b,%esi
call   1040 <fgets@plt>
lea    -0x30(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11b5 <chatdat_gen_add_user+0x55>
jmp    123f <chatdat_gen_add_user+0xdf>
lea    -0x30(%rbp),%rdi
call   1050 <chatdat_valid_username@plt>
cmp    $0x0,%eax
jne    11df <chatdat_gen_add_user+0x7f>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    120e <chatdat_gen_add_user+0xae>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <get_user@plt>
cmp    $0x0,%rax
je     1209 <chatdat_gen_add_user+0xa9>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    120e <chatdat_gen_add_user+0xae>
cmpl   $0x0,-0xc(%rbp)
jne    123f <chatdat_gen_add_user+0xdf>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <yes_no@plt>
cmp    $0x0,%rax
je     123a <chatdat_gen_add_user+0xda>
jmp    1173 <chatdat_gen_add_user+0x13>
jmp    123f <chatdat_gen_add_user+0xdf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chatdat_gen_add_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
mov    %rsp,%rbx
lea    0xe9a(%rip),%r12
lea    0xec4(%rip),%rbp
lea    0xe8e(%rip),%r13
xor    %r14d,%r14d
jmp    11bc <chatdat_gen_add_user+0x4c>
xchg   %ax,%ax
call   1030 <puts@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <yes_no@plt>
mov    $0x1,%r14b
test   %rax,%rax
je     121a <chatdat_gen_add_user+0xaa>
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1b,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    121a <chatdat_gen_add_user+0xaa>
mov    %rbx,%rdi
call   1060 <chatdat_valid_username@plt>
mov    %rbp,%rdi
test   %eax,%eax
je     11a0 <chatdat_gen_add_user+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <get_user@plt>
lea    0xea0(%rip),%rdi
test   %rax,%rax
jne    11a0 <chatdat_gen_add_user+0x30>
test   $0x1,%r14b
jne    11a5 <chatdat_gen_add_user+0x35>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.user = type { i32 }
@.str = [37 x i8] c"Enter name of new user (; to exit): \00"
@stdin = global i32 0
@.str.1 = [2 x i8] c";\00"
@.str.2 = [90 x i8] c"Invalid username. Please omit whitespace and special characters (spaces, tabs, ;, etc.).\0A\00"
@.str.3 = [37 x i8] c"The designated user already exists.\0A\00"
@.str.4 = [47 x i8] c"Would you like to try a different name? (y/n) \00"
define void @chatdat_gen_add_user(%struct.user* %0) {
%2 = alloca %struct.user*
%3 = alloca i32
%4 = alloca [27 x i8]
store %struct.user* %0, %struct.user** %2
store i32 1, i32* %3
br label %5
5: ; preds = %35, %1
%6 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 27, i32 %8)
%10 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%11 = call i64 @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %5
br label %37
14: ; preds = %5
%15 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%16 = call i32 @chatdat_valid_username(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %28
20: ; preds = %14
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%22 = load %struct.user*, %struct.user** %2
%23 = call i64 @get_user(i8* %21, %struct.user* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %27
27: ; preds = %25, %20
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%33 = call i64 (...) @yes_no()
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %5
36: ; preds = %31
br label %37
37: ; preds = %13, %36, %28
ret void
}

LLVM IR (-O2):
%struct.user = type { i32 }
@.str = [37 x i8] c"Enter name of new user (; to exit): \00"
@stdin = global i32 0
@.str.1 = [2 x i8] c";\00"
@.str.4 = [47 x i8] c"Would you like to try a different name? (y/n) \00"
@str = [89 x i8] c"Invalid username. Please omit whitespace and special characters (spaces, tabs, ;, etc.).\00"
@str.5 = [36 x i8] c"The designated user already exists.\00"
define void @chatdat_gen_add_user(%struct.user* %0) {
%2 = alloca [27 x i8]
%3 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %21, %1
%5 = phi i1 [ true, %21 ], [ false, %1 ]
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %3, i32 27, i32 %7)
%9 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %4
%12 = call i32 @chatdat_valid_username(i8* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = call i64 @get_user(i8* %3, %struct.user* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br i1 %5, label %21, label %25
18: ; preds = %14, %11
%19 = phi i8* [ getelementptr inbounds ([89 x i8], [89 x i8]* @str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0), %14 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
br label %21
21: ; preds = %18, %17
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%23 = call i64 (...) @yes_no()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %4
25: ; preds = %17, %21, %4
ret void
}