#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int,
                           unsigned int);
int /*<<< orphan*/ printf(char *);
void mv_reg_write(unsigned int reg, unsigned int value) {
  FILE *resource_dump;
  resource_dump = fopen("/proc/resource_dump", "w");
  if (!resource_dump) {
    printf("Eror opening file /proc/resource_dump\n");
    exit(-1);
  }
  fprintf(resource_dump, "register  w %08x %08x", reg, value);
  fclose(resource_dump);
  return;
}


x86 assembly (clang, -O0):
<mv_reg_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1196 <mv_reg_write+0x46>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe96(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mv_reg_write>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xeca(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1194 <mv_reg_write+0x44>
mov    %rax,%rbx
lea    0xe87(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/proc/resource_dump\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [39 x i8] c"Eror opening file /proc/resource_dump\0A\00"
@.str.3 = [22 x i8] c"register w %08x %08x\00"
define void @mv_reg_write(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15)
%17 = load i32*, i32** %5
%18 = call i32 @fclose(i32* %17)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"/proc/resource_dump\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"register w %08x %08x\00"
@str = [38 x i8] c"Eror opening file /proc/resource_dump\00"
define void @mv_reg_write(i32 %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1)
%10 = tail call i32 @fclose(i32* %3)
ret void
}