#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_L2C_lockdown(int lockdown_cpu, int lockdown_acp) {
  int f_sysfs;
  char d[14];
  sprintf(d, "%d", (int)lockdown_cpu);
  f_sysfs = open("/sys/dma_pl330/pl330_lkm_attrs/lockdown_cpu", O_WRONLY);
  if (f_sysfs < 0) {
    printf("Failed to open sysfs for lockdown_cpu.\n");
    return errno;
  }
  write(f_sysfs, &d, 14);
  close(f_sysfs);
  sprintf(d, "%d", (int)lockdown_acp);
  f_sysfs = open("/sys/dma_pl330/pl330_lkm_attrs/lockdown_acp", O_WRONLY);
  if (f_sysfs < 0) {
    printf("Failed to open sysfs for lockdown_acp.\n");
    return errno;
  }
  write(f_sysfs, &d, 14);
  close(f_sysfs);
  return 0;
}


x86 assembly (clang, -O0):
<set_L2C_lockdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1e(%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_L2C_lockdown+0x60>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <set_L2C_lockdown+0xeb>
mov    -0x10(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    -0x1e(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe29(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    121b <set_L2C_lockdown+0xcb>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <set_L2C_lockdown+0xeb>
mov    -0x10(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_L2C_lockdown>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%edx
lea    0xe9b(%rip),%rsi
lea    0xa(%rsp),%rdi
call   1070 <sprintf@plt>
mov    0x2e5a(%rip),%r15
mov    (%r15),%esi
lea    0xe83(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11e8 <set_L2C_lockdown+0x98>
mov    %eax,%ebp
lea    0xa(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe53(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    (%r15),%esi
lea    0xe6e(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11f1 <set_L2C_lockdown+0xa1>
mov    %eax,%ebx
lea    0xa(%rsp),%rsi
mov    %eax,%edi
mov    $0xe,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1206 <set_L2C_lockdown+0xb6>
lea    0xe93(%rip),%rdi
jmp    11f8 <set_L2C_lockdown+0xa8>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ddc(%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"%d\00"
@.str.1 = [44 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/lockdown_cpu\00"
@O_WRONLY = global i32 0
@.str.2 = [40 x i8] c"Failed to open sysfs for lockdown_cpu.\0A\00"
@errno = global i32 0
@.str.3 = [44 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/lockdown_acp\00"
@.str.4 = [40 x i8] c"Failed to open sysfs for lockdown_acp.\0A\00"
define i32 @set_L2C_lockdown(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [14 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [14 x i8], [14 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 ([44 x i8], [44 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 [14 x i8]* %7 to i8**
%21 = call i32 @write(i32 %19, i8** %20, i32 14)
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [14 x i8], [14 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 ([44 x i8], [44 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 [14 x i8]* %7 to i8**
%37 = call i32 @write(i32 %35, i8** %36, i32 14)
%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"%d\00"
@.str.1 = [44 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/lockdown_cpu\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.3 = [44 x i8] c"/sys/dma_pl330/pl330_lkm_attrs/lockdown_acp\00"
@str = [39 x i8] c"Failed to open sysfs for lockdown_acp.\00"
@str.5 = [39 x i8] c"Failed to open sysfs for lockdown_cpu.\00"
define i32 @set_L2C_lockdown(i32 %0, i32 %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 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 ([44 x i8], [44 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 [14 x i8]* %3 to i8**
%14 = call i32 @write(i32 %7, i8** %13, i32 14)
%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 ([44 x i8], [44 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 14)
%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
}