#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ write(int, char **, int);
int set_sdramc_priorities(unsigned int mppriority) {
  int f_sysfs;
  char d[21];
  sprintf(d, "%u", (int)mppriority);
  f_sysfs = open("/sys/dma_pl330/pl330_lkm_attrs/sdramc_priority", O_WRONLY);
  if (f_sysfs < 0) {
    printf("Failed to open sysfs for mppriority.\n");
    return errno;
  }
  write(f_sysfs, &d, 21);
  close(f_sysfs);
  return 0;
}


x86 assembly (clang, -O0):
<set_sdramc_priorities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ad <set_sdramc_priorities+0x5d>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <set_sdramc_priorities+0x7d>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sdramc_priorities>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%edx
lea    0xea2(%rip),%rsi
mov    %rsp,%rdi
call   1070 <sprintf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     119b <set_sdramc_priorities+0x4b>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x15,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11b0 <set_sdramc_priorities+0x60>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [47 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_priority\00"
@O_WRONLY = global i32 0
@.str.2 = [38 x i8] c"Failed to open sysfs for mppriority.\0A\00"
@errno = global i32 0
define i32 @set_sdramc_priorities(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [21 x i8]
store i32 %0, i32* %3
%6 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @errno
store i32 %15, i32* %2
br label %22
16: ; preds = %1
%17 = load i32, i32* %4
%18 = bitcast [21 x i8]* %5 to i8**
%19 = call i32 @write(i32 %17, i8** %18, i32 21)
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
store i32 0, i32* %2
br label %22
22: ; preds = %16, %13
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [47 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_priority\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@str = [37 x i8] c"Failed to open sysfs for mppriority.\00"
define i32 @set_sdramc_priorities(i32 %0) {
%2 = alloca [21 x i8]
%3 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @errno
br label %15
11: ; preds = %1
%12 = bitcast [21 x i8]* %2 to i8**
%13 = call i32 @write(i32 %6, i8** %12, i32 21)
%14 = tail call i32 @close(i32 %6)
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ %10, %8 ], [ 0, %11 ]
ret i32 %16
}