#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*/ nvram_close();
int /*<<< orphan*/ nvram_open_internal(int);
unsigned char nvram_read(int);
int /*<<< orphan*/ nvram_write_immediate(int, unsigned char);
int nvram_probe(int nvram_type_arg) {
  unsigned char mask;
  unsigned char nvram_cell_0x50, nvram_cell_0x53, nvram_cell_0x7f,
      nvram_cell_0xfe, nvram_cell_0xff;
  int result = 0;
  nvram_open_internal(1);
  nvram_cell_0x50 = nvram_read(0x50);
  nvram_cell_0x53 = nvram_read(0x53);
  nvram_close();
  nvram_open_internal(nvram_type_arg);
  nvram_cell_0x7f = nvram_read(0x7f);
  nvram_cell_0xfe = nvram_read(0xfe);
  nvram_cell_0xff = nvram_read(0xff);
  for (mask = 0x01; mask != 0x80; mask *= 2) {
    nvram_write_immediate(0xff, mask);
    nvram_write_immediate(0x7f, (0xa5 - mask));
    nvram_write_immediate(0xfe, (0x5a - mask));
    if (nvram_read(0xff) != mask) {
      goto nvram_probe_end;
    }
    if (nvram_read(0x7f) == mask) {
      goto nvram_probe_end;
    }
    if (nvram_read(0xfe) == mask) {
      goto nvram_probe_end;
    }
  }
  result = 1;
nvram_probe_end:
  nvram_write_immediate(0x7f, nvram_cell_0x7f);
  nvram_write_immediate(0xfe, nvram_cell_0xfe);
  nvram_write_immediate(0xff, nvram_cell_0xff);
  nvram_close();
  nvram_open_internal(1);
  nvram_write_immediate(0x50, nvram_cell_0x50);
  nvram_write_immediate(0x53, nvram_cell_0x53);
  nvram_close();
  return result;
}


x86 assembly (clang, -O0):
<nvram_probe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <nvram_open_internal@plt>
mov    $0x50,%edi
call   1050 <nvram_read@plt>
mov    %al,-0x6(%rbp)
mov    $0x53,%edi
call   1050 <nvram_read@plt>
mov    %al,-0x7(%rbp)
mov    $0x0,%al
call   1040 <nvram_close@plt>
mov    -0x4(%rbp),%edi
call   1060 <nvram_open_internal@plt>
mov    $0x7f,%edi
call   1050 <nvram_read@plt>
mov    %al,-0x8(%rbp)
mov    $0xfe,%edi
call   1050 <nvram_read@plt>
mov    %al,-0x9(%rbp)
mov    $0xff,%edi
call   1050 <nvram_read@plt>
mov    %al,-0xa(%rbp)
movb   $0x1,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x80,%eax
je     126b <nvram_probe+0x12b>
mov    $0xff,%edi
movzbl -0x5(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
movzbl -0x5(%rbp),%ecx
mov    $0xa5,%eax
sub    %ecx,%eax
mov    $0x7f,%edi
movzbl %al,%esi
call   1030 <nvram_write_immediate@plt>
movzbl -0x5(%rbp),%ecx
mov    $0x5a,%eax
sub    %ecx,%eax
mov    $0xfe,%edi
movzbl %al,%esi
call   1030 <nvram_write_immediate@plt>
mov    $0xff,%edi
call   1050 <nvram_read@plt>
movzbl %al,%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
je     121b <nvram_probe+0xdb>
jmp    1272 <nvram_probe+0x132>
mov    $0x7f,%edi
call   1050 <nvram_read@plt>
movzbl %al,%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    1239 <nvram_probe+0xf9>
jmp    1272 <nvram_probe+0x132>
mov    $0xfe,%edi
call   1050 <nvram_read@plt>
movzbl %al,%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    1257 <nvram_probe+0x117>
jmp    1272 <nvram_probe+0x132>
jmp    125c <nvram_probe+0x11c>
movzbl -0x5(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x5(%rbp)
jmp    11b0 <nvram_probe+0x70>
movl   $0x1,-0x10(%rbp)
mov    $0x7f,%edi
movzbl -0x8(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
mov    $0xfe,%edi
movzbl -0x9(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
mov    $0xff,%edi
movzbl -0xa(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
mov    $0x0,%al
call   1040 <nvram_close@plt>
mov    $0x1,%edi
call   1060 <nvram_open_internal@plt>
mov    $0x50,%edi
movzbl -0x6(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
mov    $0x53,%edi
movzbl -0x7(%rbp),%esi
call   1030 <nvram_write_immediate@plt>
mov    $0x0,%al
call   1040 <nvram_close@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvram_probe>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%edi
call   1060 <nvram_open_internal@plt>
mov    $0x50,%edi
call   1050 <nvram_read@plt>
mov    %al,0x7(%rsp)
mov    $0x53,%edi
call   1050 <nvram_read@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <nvram_close@plt>
mov    %ebx,%edi
call   1060 <nvram_open_internal@plt>
mov    $0x7f,%edi
call   1050 <nvram_read@plt>
mov    %eax,%r12d
mov    $0xfe,%edi
call   1050 <nvram_read@plt>
mov    %eax,%r13d
mov    $0xff,%edi
call   1050 <nvram_read@plt>
mov    %eax,%ebx
mov    $0x1,%r14b
nopl   0x0(%rax,%rax,1)
movzbl %r14b,%r15d
mov    $0xff,%edi
mov    %r15d,%esi
call   1030 <nvram_write_immediate@plt>
mov    $0xa5,%al
sub    %r15b,%al
movzbl %al,%esi
mov    $0x7f,%edi
call   1030 <nvram_write_immediate@plt>
mov    $0x5a,%al
sub    %r15b,%al
movzbl %al,%esi
mov    $0xfe,%edi
call   1030 <nvram_write_immediate@plt>
mov    $0xff,%edi
call   1050 <nvram_read@plt>
cmp    %r15b,%al
jne    1223 <nvram_probe+0xe3>
mov    $0x7f,%edi
call   1050 <nvram_read@plt>
cmp    %r14b,%al
je     1223 <nvram_probe+0xe3>
mov    $0xfe,%edi
call   1050 <nvram_read@plt>
cmp    %r14b,%al
je     1223 <nvram_probe+0xe3>
add    %r14b,%r14b
cmp    $0x80,%r14b
jne    11b0 <nvram_probe+0x70>
mov    $0x1,%r14d
jmp    1226 <nvram_probe+0xe6>
xor    %r14d,%r14d
mov    0x7(%rsp),%r15b
movzbl %r12b,%esi
mov    $0x7f,%edi
call   1030 <nvram_write_immediate@plt>
movzbl %r13b,%esi
mov    $0xfe,%edi
call   1030 <nvram_write_immediate@plt>
movzbl %bl,%esi
mov    $0xff,%edi
call   1030 <nvram_write_immediate@plt>
xor    %eax,%eax
call   1040 <nvram_close@plt>
mov    $0x1,%edi
call   1060 <nvram_open_internal@plt>
movzbl %r15b,%esi
mov    $0x50,%edi
call   1030 <nvram_write_immediate@plt>
movzbl %bpl,%esi
mov    $0x53,%edi
call   1030 <nvram_write_immediate@plt>
xor    %eax,%eax
call   1040 <nvram_close@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nvram_probe(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %9
%10 = call i32 @nvram_open_internal(i32 1)
%11 = call zeroext i8 @nvram_read(i32 80)
store i8 %11, i8* %4
%12 = call zeroext i8 @nvram_read(i32 83)
store i8 %12, i8* %5
%13 = call i32 (...) @nvram_close()
%14 = load i32, i32* %2
%15 = call i32 @nvram_open_internal(i32 %14)
%16 = call zeroext i8 @nvram_read(i32 127)
store i8 %16, i8* %6
%17 = call zeroext i8 @nvram_read(i32 254)
store i8 %17, i8* %7
%18 = call zeroext i8 @nvram_read(i32 255)
store i8 %18, i8* %8
store i8 1, i8* %3
br label %19
19: ; preds = %57, %1
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = icmp ne i32 %21, 128
br i1 %22, label %23, label %62
23: ; preds = %19
%24 = load i8, i8* %3
%25 = call i32 @nvram_write_immediate(i32 255, i8 zeroext %24)
%26 = load i8, i8* %3
%27 = zext i8 %26 to i32
%28 = sub nsw i32 165, %27
%29 = trunc i32 %28 to i8
%30 = call i32 @nvram_write_immediate(i32 127, i8 zeroext %29)
%31 = load i8, i8* %3
%32 = zext i8 %31 to i32
%33 = sub nsw i32 90, %32
%34 = trunc i32 %33 to i8
%35 = call i32 @nvram_write_immediate(i32 254, i8 zeroext %34)
%36 = call zeroext i8 @nvram_read(i32 255)
%37 = zext i8 %36 to i32
%38 = load i8, i8* %3
%39 = zext i8 %38 to i32
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %23
br label %63
42: ; preds = %23
%43 = call zeroext i8 @nvram_read(i32 127)
%44 = zext i8 %43 to i32
%45 = load i8, i8* %3
%46 = zext i8 %45 to i32
%47 = icmp eq i32 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %63
49: ; preds = %42
%50 = call zeroext i8 @nvram_read(i32 254)
%51 = zext i8 %50 to i32
%52 = load i8, i8* %3
%53 = zext i8 %52 to i32
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %56
55: ; preds = %49
br label %63
56: ; preds = %49
br label %57
57: ; preds = %56
%58 = load i8, i8* %3
%59 = zext i8 %58 to i32
%60 = mul nsw i32 %59, 2
%61 = trunc i32 %60 to i8
store i8 %61, i8* %3
br label %19
62: ; preds = %19
store i32 1, i32* %9
br label %63
63: ; preds = %62, %55, %48, %41
%64 = load i8, i8* %6
%65 = call i32 @nvram_write_immediate(i32 127, i8 zeroext %64)
%66 = load i8, i8* %7
%67 = call i32 @nvram_write_immediate(i32 254, i8 zeroext %66)
%68 = load i8, i8* %8
%69 = call i32 @nvram_write_immediate(i32 255, i8 zeroext %68)
%70 = call i32 (...) @nvram_close()
%71 = call i32 @nvram_open_internal(i32 1)
%72 = load i8, i8* %4
%73 = call i32 @nvram_write_immediate(i32 80, i8 zeroext %72)
%74 = load i8, i8* %5
%75 = call i32 @nvram_write_immediate(i32 83, i8 zeroext %74)
%76 = call i32 (...) @nvram_close()
%77 = load i32, i32* %9
ret i32 %77
}

LLVM IR (-O2):
define i32 @nvram_probe(i32 %0) {
%2 = tail call i32 @nvram_open_internal(i32 1)
%3 = tail call zeroext i8 @nvram_read(i32 80)
%4 = tail call zeroext i8 @nvram_read(i32 83)
%5 = tail call i32 (...) @nvram_close()
%6 = tail call i32 @nvram_open_internal(i32 %0)
%7 = tail call zeroext i8 @nvram_read(i32 127)
%8 = tail call zeroext i8 @nvram_read(i32 254)
%9 = tail call zeroext i8 @nvram_read(i32 255)
br label %12
10: ; preds = %24
%11 = icmp eq i8 %27, -128
br i1 %11, label %28, label %12
12: ; preds = %1, %10
%13 = phi i8 [ 1, %1 ], [ %27, %10 ]
%14 = tail call i32 @nvram_write_immediate(i32 255, i8 zeroext %13)
%15 = sub i8 -91, %13
%16 = tail call i32 @nvram_write_immediate(i32 127, i8 zeroext %15)
%17 = sub i8 90, %13
%18 = tail call i32 @nvram_write_immediate(i32 254, i8 zeroext %17)
%19 = tail call zeroext i8 @nvram_read(i32 255)
%20 = icmp eq i8 %19, %13
br i1 %20, label %21, label %28
21: ; preds = %12
%22 = tail call zeroext i8 @nvram_read(i32 127)
%23 = icmp eq i8 %22, %13
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = tail call zeroext i8 @nvram_read(i32 254)
%26 = icmp eq i8 %25, %13
%27 = shl i8 %13, 1
br i1 %26, label %28, label %10
28: ; preds = %10, %24, %21, %12
%29 = phi i32 [ 0, %12 ], [ 0, %21 ], [ 0, %24 ], [ 1, %10 ]
%30 = tail call i32 @nvram_write_immediate(i32 127, i8 zeroext %7)
%31 = tail call i32 @nvram_write_immediate(i32 254, i8 zeroext %8)
%32 = tail call i32 @nvram_write_immediate(i32 255, i8 zeroext %9)
%33 = tail call i32 (...) @nvram_close()
%34 = tail call i32 @nvram_open_internal(i32 1)
%35 = tail call i32 @nvram_write_immediate(i32 80, i8 zeroext %3)
%36 = tail call i32 @nvram_write_immediate(i32 83, i8 zeroext %4)
%37 = tail call i32 (...) @nvram_close()
ret i32 %29
}