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

/* Variables and functions */
char *carmel_getenv(char *);
int /*<<< orphan*/ carmel_setenv(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ console_readline(char *, char *, int);
scalar_t__ lib_strcmp(char *, char *);
int /*<<< orphan*/ lib_strupr(char *);
int /*<<< orphan*/ xprintf(char *);
int /*<<< orphan*/ xsprintf(char *, char *, char *, char *);
int msetup_getone(char *prompt, char *envvar, char *defval, int flg) {
  char buffer[100];
  char pbuf[100];
  char *curval;
  curval = carmel_getenv(envvar);
  if (!curval)
    curval = defval;
  xsprintf(pbuf, "%s [%s]: ", prompt, curval);
  for (;;) {
    console_readline(pbuf, buffer, sizeof(buffer));
    if (buffer[0] == 0)
      break;
    if (flg & (1 | 2))
      lib_strupr(buffer);
    if (flg & 2) {
      if (lib_strcmp(buffer, "YES") == 0)
        break;
      if (lib_strcmp(buffer, "NO") == 0)
        break;
      xprintf("You must enter 'YES' or 'NO'.\n");
      continue;
    }
    break;
  }
  if (buffer[0] == 0) {
    carmel_setenv(envvar, defval, 0);
  } else {
    carmel_setenv(envvar, buffer, 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<msetup_getone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <carmel_getenv@plt>
mov    %rax,-0xf8(%rbp)
cmpq   $0x0,-0xf8(%rbp)
jne    11b3 <msetup_getone+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xf8(%rbp),%rcx
lea    0xe34(%rip),%rsi
call   1040 <xsprintf@plt>
lea    -0xf0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1030 <console_readline@plt>
movsbl -0x80(%rbp),%eax
cmp    $0x0,%eax
jne    11f8 <msetup_getone+0x88>
jmp    1273 <msetup_getone+0x103>
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1210 <msetup_getone+0xa0>
lea    -0x80(%rbp),%rdi
call   1070 <lib_strupr@plt>
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     126e <msetup_getone+0xfe>
lea    -0x80(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1090 <lib_strcmp@plt>
cmp    $0x0,%rax
jne    123e <msetup_getone+0xce>
jmp    1273 <msetup_getone+0x103>
lea    -0x80(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1090 <lib_strcmp@plt>
cmp    $0x0,%rax
jne    125d <msetup_getone+0xed>
jmp    1273 <msetup_getone+0x103>
lea    0xdad(%rip),%rdi
call   1080 <xprintf@plt>
jmp    11d1 <msetup_getone+0x61>
jmp    1273 <msetup_getone+0x103>
movsbl -0x80(%rbp),%eax
cmp    $0x0,%eax
jne    1294 <msetup_getone+0x124>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <carmel_setenv@plt>
jmp    12a3 <msetup_getone+0x133>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
xor    %edx,%edx
call   1050 <carmel_setenv@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msetup_getone>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rdi,%r15
mov    %rsi,(%rsp)
mov    %rsi,%rdi
call   1060 <carmel_getenv@plt>
test   %rax,%rax
mov    %rbx,0x8(%rsp)
cmove  %rbx,%rax
lea    0xe58(%rip),%rsi
lea    0x80(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <xsprintf@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x64,%edx
call   1030 <console_readline@plt>
cmpb   $0x0,0x10(%rsp)
je     1267 <msetup_getone+0xf7>
lea    0xe28(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xe20(%rip),%r13
lea    0xe1c(%rip),%r14
lea    0x80(%rsp),%r15
nopl   (%rax)
test   $0x3,%bpl
je     120e <msetup_getone+0x9e>
mov    %rbx,%rdi
call   1070 <lib_strupr@plt>
test   $0x2,%bpl
je     1255 <msetup_getone+0xe5>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <lib_strcmp@plt>
test   %rax,%rax
je     1255 <msetup_getone+0xe5>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <lib_strcmp@plt>
test   %rax,%rax
je     1255 <msetup_getone+0xe5>
mov    %r14,%rdi
call   1080 <xprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1030 <console_readline@plt>
cmpb   $0x0,0x10(%rsp)
jne    1200 <msetup_getone+0x90>
jmp    1267 <msetup_getone+0xf7>
cmpb   $0x0,0x10(%rsp)
je     1267 <msetup_getone+0xf7>
lea    0x10(%rsp),%rsi
mov    (%rsp),%rdi
jmp    1270 <msetup_getone+0x100>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <carmel_setenv@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s [%s]: \00"
@.str.1 = [4 x i8] c"YES\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [31 x i8] c"You must enter 'YES' or 'NO'.\0A\00"
define i32 @msetup_getone(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [100 x i8]
%10 = alloca [100 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i8*, i8** %6
%13 = call i8* @carmel_getenv(i8* %12)
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = icmp ne i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %4
%17 = load i8*, i8** %7
store i8* %17, i8** %11
br label %18
18: ; preds = %16, %4
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = load i8*, i8** %11
%22 = call i32 @xsprintf(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
br label %23
23: ; preds = %53, %18
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%26 = call i32 @console_readline(i8* %24, i8* %25, i32 100)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %23
br label %56
32: ; preds = %23
%33 = load i32, i32* %8
%34 = and i32 %33, 3
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%38 = call i32 @lib_strupr(i8* %37)
br label %39
39: ; preds = %36, %32
%40 = load i32, i32* %8
%41 = and i32 %40, 2
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%45 = call i64 @lib_strcmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
br label %56
48: ; preds = %43
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%50 = call i64 @lib_strcmp(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
br label %56
53: ; preds = %48
%54 = call i32 @xprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %23
55: ; preds = %39
br label %56
56: ; preds = %55, %52, %47, %31
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i8*, i8** %6
%63 = load i8*, i8** %7
%64 = call i32 @carmel_setenv(i8* %62, i8* %63, i32 0)
br label %69
65: ; preds = %56
%66 = load i8*, i8** %6
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%68 = call i32 @carmel_setenv(i8* %66, i8* %67, i32 0)
br label %69
69: ; preds = %65, %61
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s [%s]: \00"
@.str.1 = [4 x i8] c"YES\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [31 x i8] c"You must enter 'YES' or 'NO'.\0A\00"
define i32 @msetup_getone(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%9 = tail call i8* @carmel_getenv(i8* %1)
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* %2, i8* %9
%12 = call i32 @xsprintf(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
%13 = call i32 @console_readline(i8* %8, i8* %7, i32 100)
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %4
%17 = and i32 %3, 3
%18 = icmp eq i32 %17, 0
%19 = and i32 %3, 2
%20 = icmp eq i32 %19, 0
br label %21
21: ; preds = %16, %31
br i1 %18, label %24, label %22
22: ; preds = %21
%23 = call i32 @lib_strupr(i8* %7)
br label %24
24: ; preds = %22, %21
br i1 %20, label %36, label %25
25: ; preds = %24
%26 = call i64 @lib_strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %25
%29 = call i64 @lib_strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = call i32 @xprintf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @console_readline(i8* %8, i8* %7, i32 100)
%34 = load i8, i8* %7
%35 = icmp eq i8 %34, 0
br i1 %35, label %39, label %21
36: ; preds = %24, %28, %25
%37 = load i8, i8* %7
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31, %4, %36
%40 = call i32 @carmel_setenv(i8* %1, i8* %2, i32 0)
br label %43
41: ; preds = %36
%42 = call i32 @carmel_setenv(i8* %1, i8* %7, i32 0)
br label %43
43: ; preds = %41, %39
ret i32 0
}