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


x86 assembly (clang, -O0):
<nvram_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <nvram_get_option@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <nvram_init@plt>
mov    -0x20(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11a5 <nvram_set+0x55>
mov    $0x0,%al
call   1050 <nvram_close@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <nvram_set+0xc6>
mov    -0x20(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11f9 <nvram_set+0xa9>
mov    -0x10(%rbp),%rdi
call   1070 <nvram_get@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f4 <nvram_set+0xa4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f4 <nvram_set+0xa4>
mov    $0x0,%al
call   1050 <nvram_close@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <nvram_set+0xc6>
jmp    11f9 <nvram_set+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <_nvram_set@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <nvram_close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvram_set>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <nvram_get_option@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1060 <nvram_init@plt>
test   %ebp,%ebp
js     11ac <nvram_set+0x5c>
test   $0x2,%bpl
je     1194 <nvram_set+0x44>
mov    %rbx,%rdi
call   1070 <nvram_get@plt>
test   %rax,%rax
je     1194 <nvram_set+0x44>
cmpb   $0x0,(%rax)
je     1194 <nvram_set+0x44>
xor    %eax,%eax
call   1050 <nvram_close@plt>
mov    0x2e56(%rip),%rax
jmp    11ba <nvram_set+0x6a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <_nvram_set@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <nvram_close@plt>
mov    %ebx,%eax
jmp    11bc <nvram_set+0x6c>
xor    %eax,%eax
call   1050 <nvram_close@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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