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


x86 assembly (clang, -O0):
<set_sdramc_weights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe94(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b0 <set_sdramc_weights+0x60>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <set_sdramc_weights+0xeb>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe29(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    121b <set_sdramc_weights+0xcb>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <set_sdramc_weights+0xeb>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    -0x10(%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_weights>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%edx
lea    0xe9b(%rip),%rsi
mov    %rsp,%rdi
call   1070 <sprintf@plt>
mov    0x2e5c(%rip),%r15
mov    (%r15),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11e2 <set_sdramc_weights+0x92>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x15,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    (%r15),%esi
lea    0xe74(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11eb <set_sdramc_weights+0x9b>
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    1200 <set_sdramc_weights+0xb0>
lea    0xe9d(%rip),%rdi
jmp    11f2 <set_sdramc_weights+0xa2>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [46 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_weight0\00"
@O_WRONLY = global i32 0
@.str.2 = [40 x i8] c"Failed to open sysfs for mpweight_0_4.\0A\00"
@errno = global i32 0
@.str.3 = [46 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_weight1\00"
@.str.4 = [40 x i8] c"Failed to open sysfs for mpweight_1_4.\0A\00"
define i32 @set_sdramc_weights(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [21 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @errno
store i32 %17, i32* %3
br label %40
18: ; preds = %2
%19 = load i32, i32* %6
%20 = bitcast [21 x i8]* %7 to i8**
%21 = call i32 @write(i32 %19, i8** %20, i32 21)
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @O_WRONLY
%28 = call i32 @open(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* @errno
store i32 %33, i32* %3
br label %40
34: ; preds = %18
%35 = load i32, i32* %6
%36 = bitcast [21 x i8]* %7 to i8**
%37 = call i32 @write(i32 %35, i8** %36, i32 21)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
store i32 0, i32* %3
br label %40
40: ; preds = %34, %31, %15
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [46 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_weight0\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.3 = [46 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/sdramc_weight1\00"
@str = [39 x i8] c"Failed to open sysfs for mpweight_1_4.\00"
@str.5 = [39 x i8] c"Failed to open sysfs for mpweight_0_4.\00"
define i32 @set_sdramc_weights(i32 %0, i32 %1) {
%3 = alloca [21 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @O_WRONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
%11 = load i32, i32* @errno
br label %26
12: ; preds = %2
%13 = bitcast [21 x i8]* %3 to i8**
%14 = call i32 @write(i32 %7, i8** %13, i32 21)
%15 = tail call i32 @close(i32 %7)
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%17 = load i32, i32* @O_WRONLY
%18 = tail call i32 @open(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%22 = load i32, i32* @errno
br label %26
23: ; preds = %12
%24 = call i32 @write(i32 %18, i8** %13, i32 21)
%25 = tail call i32 @close(i32 %18)
br label %26
26: ; preds = %23, %20, %9
%27 = phi i32 [ %11, %9 ], [ %22, %20 ], [ 0, %23 ]
ret i32 %27
}