#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*/ mode_set(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                            char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ text_input(char *, char *, int, int /*<<< orphan*/ *);
int userdb_add(char *, char *);
scalar_t__ userdb_find_byname(char *);
int /*<<< orphan*/ userdb_set_password(int, char *);
int setup_add_owner(void) {
  char name[32], mask[256], pass[32];
  int id;
  putchar('\n');
  printf("This will add an owner to your database.\n\n");
  printf("It is important for security that you use the most specific\n");
  printf("mask possible.\n\n");
  printf("It is highly recommended that you set a password for this\n");
  printf("user.  Users with passwords will have to authenticate with\n");
  printf("the bot using the `auth' command before using any privileged\n");
  printf("commands.\n\n");
  text_input("Handle", name, 32, NULL);
  text_input("Mask", mask, 256, NULL);
  system("stty -echo");
  text_input("Password", pass, 32, NULL);
  system("stty echo");
  printf("\n\n");
  if ((name[0] == 0) || (mask[0] == 0)) {
    printf("Canceled.\n");
    return -1;
  }
  if (userdb_find_byname(name)) {
    printf("User `%s' already exists.\n", name);
  } else {
    id = userdb_add(name, mask);
    if (id == 0) {
      printf("Could not add bot user `%s' to database.\n", name);
      return -1;
    }
    printf("Added owner `%s' with mask `%s'.\n", name, mask);
    mode_set(id, NULL, NULL, "+w", NULL);
    if (pass[0] != 0) {
      userdb_set_password(id, pass);
      printf("Set password.\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_add_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xf0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xf3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xf38(%rip),%rdi
mov    $0x20,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <text_input@plt>
lea    -0x130(%rbp),%rsi
lea    0xf23(%rip),%rdi
mov    $0x100,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <text_input@plt>
lea    0xf13(%rip),%rdi
call   1050 <system@plt>
lea    -0x150(%rbp),%rsi
lea    0xf0b(%rip),%rdi
mov    $0x20,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <text_input@plt>
lea    0xeff(%rip),%rdi
call   1050 <system@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
je     128b <setup_add_owner+0x10b>
movsbl -0x130(%rbp),%eax
cmp    $0x0,%eax
jne    12a5 <setup_add_owner+0x125>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <setup_add_owner+0x202>
lea    -0x30(%rbp),%rdi
call   1080 <userdb_find_byname@plt>
cmp    $0x0,%rax
je     12cf <setup_add_owner+0x14f>
lea    -0x30(%rbp),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    137b <setup_add_owner+0x1fb>
lea    -0x30(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1090 <userdb_add@plt>
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jne    1310 <setup_add_owner+0x190>
lea    -0x30(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <setup_add_owner+0x202>
lea    -0x30(%rbp),%rsi
lea    -0x130(%rbp),%rdx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x154(%rbp),%edi
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe9b(%rip),%rcx
mov    %r8,%rsi
mov    %r8,%rdx
call   10a0 <mode_set@plt>
movsbl -0x150(%rbp),%eax
cmp    $0x0,%eax
je     1376 <setup_add_owner+0x1f6>
mov    -0x154(%rbp),%edi
lea    -0x150(%rbp),%rsi
call   1040 <userdb_set_password@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    137b <setup_add_owner+0x1fb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_add_owner>:
push   %rbp
push   %rbx
sub    $0x148,%rsp
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeea(%rip),%rdi
call   1040 <puts@plt>
lea    0xf08(%rip),%rdi
call   1040 <puts@plt>
lea    0xf38(%rip),%rdi
call   1040 <puts@plt>
lea    0xf3c(%rip),%rdi
call   1040 <puts@plt>
lea    0xf6a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf99(%rip),%rdi
call   1040 <puts@plt>
lea    0xfca(%rip),%rdi
call   1040 <puts@plt>
lea    0xe02(%rip),%rdi
mov    %rsp,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1080 <text_input@plt>
lea    0xdf3(%rip),%rdi
lea    0x40(%rsp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1080 <text_input@plt>
lea    0xde0(%rip),%rdi
call   1060 <system@plt>
lea    0xddf(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1080 <text_input@plt>
lea    0xdd0(%rip),%rdi
call   1060 <system@plt>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
cmpb   $0x0,(%rsp)
je     1290 <setup_add_owner+0x100>
cmpb   $0x0,0x40(%rsp)
je     1290 <setup_add_owner+0x100>
mov    %rsp,%rdi
call   1090 <userdb_find_byname@plt>
test   %rax,%rax
je     12ad <setup_add_owner+0x11d>
lea    0xda8(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a1 <setup_add_owner+0x111>
lea    0xf3e(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x148,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rsp,%rdi
lea    0x40(%rsp),%rsi
call   10a0 <userdb_add@plt>
test   %eax,%eax
je     130e <setup_add_owner+0x17e>
mov    %eax,%ebp
lea    0xda8(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
lea    0x40(%rsp),%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb2(%rip),%rcx
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %r8d,%r8d
call   10b0 <mode_set@plt>
cmpb   $0x0,0x20(%rsp)
je     12a1 <setup_add_owner+0x111>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
call   1050 <userdb_set_password@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
jmp    12a1 <setup_add_owner+0x111>
lea    0xd30(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    129c <setup_add_owner+0x10c>

LLVM IR (-O0):
@.str = [43 x i8] c"This will add an owner to your database.\0A\0A\00"
@.str.1 = [61 x i8] c"It is important for security that you use the most specific\0A\00"
@.str.2 = [17 x i8] c"mask possible.\0A\0A\00"
@.str.3 = [59 x i8] c"It is highly recommended that you set a password for this\0A\00"
@.str.4 = [60 x i8] c"user. Users with passwords will have to authenticate with\0A\00"
@.str.5 = [62 x i8] c"the bot using the `auth' command before using any privileged\0A\00"
@.str.6 = [12 x i8] c"commands.\0A\0A\00"
@.str.7 = [7 x i8] c"Handle\00"
@.str.8 = [5 x i8] c"Mask\00"
@.str.9 = [11 x i8] c"stty -echo\00"
@.str.10 = [9 x i8] c"Password\00"
@.str.11 = [10 x i8] c"stty echo\00"
@.str.12 = [3 x i8] c"\0A\0A\00"
@.str.13 = [11 x i8] c"Canceled.\0A\00"
@.str.14 = [27 x i8] c"User `%s' already exists.\0A\00"
@.str.15 = [42 x i8] c"Could not add bot user `%s' to database.\0A\00"
@.str.16 = [34 x i8] c"Added owner `%s' with mask `%s'.\0A\00"
@.str.17 = [3 x i8] c"+w\00"
@.str.18 = [15 x i8] c"Set password.\0A\00"
define i32 @setup_add_owner() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [256 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = call i32 @putchar(i8 signext 10)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%15 = call i32 @text_input(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %14, i32 32, i32* null)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 @text_input(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %16, i32 256, i32* null)
%18 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%20 = call i32 @text_input(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %19, i32 32, i32* null)
%21 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27, %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
34: ; preds = %27
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%36 = call i64 @userdb_find_byname(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %39)
br label %66
41: ; preds = %34
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%44 = call i32 @userdb_add(i8* %42, i8* %43)
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i8* %48)
store i32 -1, i32* %1
br label %67
50: ; preds = %41
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i32, i32* %5
%55 = call i32 @mode_set(i32 %54, i32* null, i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i32* null)
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %50
%61 = load i32, i32* %5
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%63 = call i32 @userdb_set_password(i32 %61, i8* %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0))
br label %65
65: ; preds = %60, %50
br label %66
66: ; preds = %65, %38
store i32 0, i32* %1
br label %67
67: ; preds = %66, %47, %32
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str.7 = [7 x i8] c"Handle\00"
@.str.8 = [5 x i8] c"Mask\00"
@.str.9 = [11 x i8] c"stty -echo\00"
@.str.10 = [9 x i8] c"Password\00"
@.str.11 = [10 x i8] c"stty echo\00"
@.str.14 = [27 x i8] c"User `%s' already exists.\0A\00"
@.str.15 = [42 x i8] c"Could not add bot user `%s' to database.\0A\00"
@.str.16 = [34 x i8] c"Added owner `%s' with mask `%s'.\0A\00"
@.str.17 = [3 x i8] c"+w\00"
@str = [42 x i8] c"This will add an owner to your database.\0A\00"
@str.19 = [60 x i8] c"It is important for security that you use the most specific\00"
@str.20 = [16 x i8] c"mask possible.\0A\00"
@str.21 = [58 x i8] c"It is highly recommended that you set a password for this\00"
@str.22 = [59 x i8] c"user. Users with passwords will have to authenticate with\00"
@str.23 = [61 x i8] c"the bot using the `auth' command before using any privileged\00"
@str.24 = [11 x i8] c"commands.\0A\00"
@str.25 = [2 x i8] c"\0A\00"
@str.26 = [14 x i8] c"Set password.\00"
@str.27 = [10 x i8] c"Canceled.\00"
define i32 @setup_add_owner() {
%1 = alloca [32 x i8]
%2 = alloca [256 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @putchar(i8 signext 10)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.19, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.20, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.21, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.22, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.23, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.24, i64 0, i64 0))
%15 = call i32 @text_input(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %4, i32 32, i32* null)
%16 = call i32 @text_input(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %5, i32 256, i32* null)
%17 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%18 = call i32 @text_input(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %6, i32 32, i32* null)
%19 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.25, i64 0, i64 0))
%21 = load i8, i8* %4
%22 = icmp eq i8 %21, 0
%23 = load i8, i8* %5
%24 = icmp eq i8 %23, 0
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.27, i64 0, i64 0))
br label %46
28: ; preds = %0
%29 = call i64 @userdb_find_byname(i8* %4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %4)
br label %46
33: ; preds = %28
%34 = call i32 @userdb_add(i8* %4, i8* %5)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i8* %4)
br label %46
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %4, i8* %5)
%40 = call i32 @mode_set(i32 %34, i32* null, i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i32* null)
%41 = load i8, i8* %6
%42 = icmp eq i8 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = call i32 @userdb_set_password(i32 %34, i8* %6)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.26, i64 0, i64 0))
br label %46
46: ; preds = %31, %43, %38, %36, %26
%47 = phi i32 [ -1, %26 ], [ -1, %36 ], [ 0, %38 ], [ 0, %43 ], [ 0, %31 ]
ret i32 %47
}