#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int pwrite(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void wrnb(char *pci, uint32_t reg, uint32_t data) {
  int fd = open(pci, O_WRONLY);
  if (pwrite(fd, &data, sizeof data, reg) != sizeof data) {
    fprintf(stderr, "Failed to write data to northbridge register %s\n", pci);
    close(fd);
    exit(EXIT_FAILURE);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<wrnb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%ecx
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <pwrite@plt>
cltq
cmp    $0x4,%rax
je     11c6 <wrnb+0x76>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrnb>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %edx,0xc(%rsp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
mov    %ebx,%ecx
call   1050 <pwrite@plt>
cmp    $0x4,%eax
jne    1198 <wrnb+0x48>
mov    %ebp,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <close@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Failed to write data to northbridge register %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @wrnb(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = call i32 @pwrite(i32 %11, i32* %6, i32 4, i32 %12)
%14 = sext i32 %13 to i64
%15 = icmp ne i64 %14, 4
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %7
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %3
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Failed to write data to northbridge register %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @wrnb(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %2, i32* %4
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = call i32 @pwrite(i32 %6, i32* %4, i32 4, i32 %1)
%8 = icmp eq i32 %7, 4
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @close(i32 %6)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %3
%16 = tail call i32 @close(i32 %6)
ret void
}