#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 EACCES;
int EINVAL;
int _nvram_set(char const *, char const *);
char *nvram_get(char const *);
unsigned int nvram_get_option(char const *);
int nvram_set_boot(const char *name, const char *value) {
  unsigned int opt = nvram_get_option(name);
  int ret = 0;
  if (opt & 0x80000000) {
    return EINVAL;
  }
  if (opt & 0x02) {
    char *exist = nvram_get(name);
    if (exist && *exist) {
      return EACCES;
    }
  }
  ret = _nvram_set(name, value);
  return ret;
}


x86 assembly (clang, -O0):
<nvram_set_boot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <nvram_get_option@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1175 <nvram_set_boot+0x45>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <nvram_set_boot+0xa8>
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11c2 <nvram_set_boot+0x92>
mov    -0x10(%rbp),%rdi
call   1050 <nvram_get@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bd <nvram_set_boot+0x8d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bd <nvram_set_boot+0x8d>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <nvram_set_boot+0xa8>
jmp    11c2 <nvram_set_boot+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <_nvram_set@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvram_set_boot>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <nvram_get_option@plt>
test   %eax,%eax
js     1174 <nvram_set_boot+0x44>
test   $0x2,%al
je     1162 <nvram_set_boot+0x32>
mov    %rbx,%rdi
call   1050 <nvram_get@plt>
test   %rax,%rax
je     1162 <nvram_set_boot+0x32>
cmpb   $0x0,(%rax)
je     1162 <nvram_set_boot+0x32>
mov    0x2e88(%rip),%rax
jmp    117b <nvram_set_boot+0x4b>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <_nvram_set@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@EACCES = global i32 0
define i32 @nvram_set_boot(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @nvram_get_option(i8* %9)
store i32 %10, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %6
%12 = and i32 %11, -2147483648
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @EINVAL
store i32 %15, i32* %3
br label %38
16: ; preds = %2
%17 = load i32, i32* %6
%18 = and i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = call i8* @nvram_get(i8* %21)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i32, i32* @EACCES
store i32 %31, i32* %3
br label %38
32: ; preds = %25, %20
br label %33
33: ; preds = %32, %16
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 @_nvram_set(i8* %34, i8* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
store i32 %37, i32* %3
br label %38
38: ; preds = %33, %30, %14
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@EINVAL = global i32 0
@EACCES = global i32 0
define i32 @nvram_set_boot(i8* %0, i8* %1) {
%3 = tail call i32 @nvram_get_option(i8* %0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = load i32, i32* @EINVAL
br label %19
7: ; preds = %2
%8 = and i32 %3, 2
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i8* @nvram_get(i8* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
%16 = load i32, i32* @EACCES
br i1 %15, label %17, label %19
17: ; preds = %10, %13, %7
%18 = tail call i32 @_nvram_set(i8* %0, i8* %1)
br label %19
19: ; preds = %13, %17, %5
%20 = phi i32 [ %6, %5 ], [ %18, %17 ], [ %16, %13 ]
ret i32 %20
}