#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 TwMasterTransact(int, unsigned char *, int, int /*<<< orphan*/,
                     int /*<<< orphan*/, int /*<<< orphan*/);
int NvMemWriteEnable(int on) {
  int rc;
  unsigned char buf[3];
  buf[0] = 0;
  buf[1] = 0x3F;
  if (on) {
    buf[2] = 0x02;
    if ((rc = TwMasterTransact(0x6F, buf, 3, 0, 0, 0)) == 0) {
      buf[2] = 0x06;
      rc = TwMasterTransact(0x6F, buf, 3, 0, 0, 0);
    }
  } else {
    buf[2] = 0x00;
    rc = TwMasterTransact(0x6F, buf, 3, 0, 0, 0);
  }
  return rc;
}


x86 assembly (clang, -O0):
<NvMemWriteEnable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0xb(%rbp)
movb   $0x3f,-0xa(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1181 <NvMemWriteEnable+0x71>
movb   $0x2,-0x9(%rbp)
lea    -0xb(%rbp),%rsi
mov    $0x6f,%edi
mov    $0x3,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1030 <TwMasterTransact@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    117c <NvMemWriteEnable+0x6c>
movb   $0x6,-0x9(%rbp)
lea    -0xb(%rbp),%rsi
mov    $0x6f,%edi
mov    $0x3,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1030 <TwMasterTransact@plt>
mov    %eax,-0x8(%rbp)
jmp    11a4 <NvMemWriteEnable+0x94>
movb   $0x0,-0x9(%rbp)
lea    -0xb(%rbp),%rsi
mov    $0x6f,%edi
mov    $0x3,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1030 <TwMasterTransact@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NvMemWriteEnable>:
push   %rax
movw   $0x3f00,0x5(%rsp)
test   %edi,%edi
je     1143 <NvMemWriteEnable+0x33>
movb   $0x2,0x7(%rsp)
lea    0x5(%rsp),%rsi
mov    $0x6f,%edi
mov    $0x3,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <TwMasterTransact@plt>
test   %eax,%eax
je     1147 <NvMemWriteEnable+0x37>
pop    %rcx
ret
xor    %eax,%eax
jmp    1149 <NvMemWriteEnable+0x39>
mov    $0x6,%al
mov    %al,0x7(%rsp)
lea    0x5(%rsp),%rsi
mov    $0x6f,%edi
mov    $0x3,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <TwMasterTransact@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @NvMemWriteEnable(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
store i8 0, i8* %5
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 63, i8* %6
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 2, i8* %10
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%12 = call i32 @TwMasterTransact(i32 111, i8* %11, i32 3, i32 0, i32 0, i32 0)
store i32 %12, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 6, i8* %15
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%17 = call i32 @TwMasterTransact(i32 111, i8* %16, i32 3, i32 0, i32 0, i32 0)
store i32 %17, i32* %3
br label %18
18: ; preds = %14, %9
br label %23
19: ; preds = %1
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %20
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%22 = call i32 @TwMasterTransact(i32 111, i8* %21, i32 3, i32 0, i32 0, i32 0)
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %18
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @NvMemWriteEnable(i32 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 63, i8* %4
%5 = icmp eq i32 %0, 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
br i1 %5, label %10, label %7
7: ; preds = %1
store i8 2, i8* %6
%8 = call i32 @TwMasterTransact(i32 111, i8* %3, i32 3, i32 0, i32 0, i32 0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1, %7
%11 = phi i8 [ 6, %7 ], [ 0, %1 ]
store i8 %11, i8* %6
%12 = call i32 @TwMasterTransact(i32 111, i8* %3, i32 3, i32 0, i32 0, i32 0)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ %8, %7 ], [ %12, %10 ]
ret i32 %14
}