#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 sscanf(char const *, char *, int *);
int /*<<< orphan*/ strcasecmp(char const *, char *);
int set_boolean_var(int *var, const char *val) {
  int v = -1;
  if (!val)
    return (*var = !*var);
  if (sscanf(val, "%d", &v) != 1) {
    if (!strcasecmp(val, "off"))
      v = 0;
    else if (!strcasecmp(val, "false"))
      v = 0;
    else if (!strcasecmp(val, "on"))
      v = 1;
    else if (!strcasecmp(val, "true"))
      v = 1;
  }
  if (v == 0 || v == 1)
    return (*var = v);
  else
    return -1;
}


x86 assembly (clang, -O0):
<set_boolean_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <set_boolean_var+0x41>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x4(%rbp)
jmp    124d <set_boolean_var+0x12d>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1221 <set_boolean_var+0x101>
mov    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11a3 <set_boolean_var+0x83>
movl   $0x0,-0x1c(%rbp)
jmp    121c <set_boolean_var+0xfc>
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11c8 <set_boolean_var+0xa8>
movl   $0x0,-0x1c(%rbp)
jmp    1217 <set_boolean_var+0xf7>
mov    -0x18(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11ed <set_boolean_var+0xcd>
movl   $0x1,-0x1c(%rbp)
jmp    1212 <set_boolean_var+0xf2>
mov    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    120d <set_boolean_var+0xed>
movl   $0x1,-0x1c(%rbp)
jmp    1212 <set_boolean_var+0xf2>
jmp    1217 <set_boolean_var+0xf7>
jmp    121c <set_boolean_var+0xfc>
jmp    1221 <set_boolean_var+0x101>
cmpl   $0x0,-0x1c(%rbp)
je     1235 <set_boolean_var+0x115>
cmpl   $0x1,-0x1c(%rbp)
jne    1246 <set_boolean_var+0x126>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x4(%rbp)
jmp    124d <set_boolean_var+0x12d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_boolean_var>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movl   $0xffffffff,0xc(%rsp)
ff
test   %rsi,%rsi
je     1164 <set_boolean_var+0x44>
mov    %rsi,%rbx
lea    0xebe(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1170 <set_boolean_var+0x50>
mov    0xc(%rsp),%ebp
mov    $0xffffffff,%eax
cmp    $0x1,%ebp
jbe    11c3 <set_boolean_var+0xa3>
jmp    11c8 <set_boolean_var+0xa8>
xor    %ebp,%ebp
cmpl   $0x0,(%r14)
sete   %bpl
jmp    11c3 <set_boolean_var+0xa3>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11c3 <set_boolean_var+0xa3>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11c3 <set_boolean_var+0xa3>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     11c3 <set_boolean_var+0xa3>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    1154 <set_boolean_var+0x34>
mov    %ebp,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"off\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [3 x i8] c"on\00"
@.str.4 = [5 x i8] c"true\00"
define i32 @set_boolean_var(i32* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* %0
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
br label %28
10: ; preds = %2
%11 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = icmp eq i32 %11, 1
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22, %10
%26 = load i32, i32* %3
%27 = icmp ult i32 %26, 2
br i1 %27, label %28, label %30
28: ; preds = %25, %13, %16, %19, %22, %6
%29 = phi i32 [ %9, %6 ], [ %26, %25 ], [ 0, %13 ], [ 0, %16 ], [ 1, %19 ], [ 1, %22 ]
store i32 %29, i32* %0
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ -1, %25 ], [ %29, %28 ]
ret i32 %31
}