#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*/ prussdrv_pru_disable(int);
int /*<<< orphan*/ prussdrv_pru_enable(int);
int /*<<< orphan*/ prussdrv_pru_write_memory(unsigned int, int /*<<< orphan*/,
                                             unsigned int const *, int);
int prussdrv_exec_code(int prunum, const unsigned int *code, int codelen) {
  unsigned int pru_ram_id;
  if (prunum == 0)
    pru_ram_id = 2;
  else if (prunum == 1)
    pru_ram_id = 3;
  else
    return -1;
  prussdrv_pru_disable(prunum);
  prussdrv_pru_write_memory(pru_ram_id, 0, code, codelen);
  prussdrv_pru_enable(prunum);
  return 0;
}


x86 assembly (clang, -O0):
<prussdrv_exec_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1158 <prussdrv_exec_code+0x28>
movl   $0x2,-0x18(%rbp)
jmp    117f <prussdrv_exec_code+0x4f>
cmpl   $0x1,-0x8(%rbp)
jne    116e <prussdrv_exec_code+0x3e>
movl   $0x3,-0x18(%rbp)
jmp    117a <prussdrv_exec_code+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <prussdrv_exec_code+0x77>
jmp    117f <prussdrv_exec_code+0x4f>
mov    -0x8(%rbp),%edi
call   1040 <prussdrv_pru_disable@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <prussdrv_pru_write_memory@plt>
mov    -0x8(%rbp),%edi
call   1030 <prussdrv_pru_enable@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prussdrv_exec_code>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebx
test   %edi,%edi
je     1156 <prussdrv_exec_code+0x26>
mov    $0xffffffff,%ebp
cmp    $0x1,%ebx
jne    117c <prussdrv_exec_code+0x4c>
mov    $0x3,%r12d
jmp    115c <prussdrv_exec_code+0x2c>
mov    $0x2,%r12d
mov    %ebx,%edi
call   1040 <prussdrv_pru_disable@plt>
xor    %ebp,%ebp
mov    %r12d,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <prussdrv_pru_write_memory@plt>
mov    %ebx,%edi
call   1030 <prussdrv_pru_enable@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @prussdrv_exec_code(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 2, i32* %8
br label %18
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 3, i32* %8
br label %17
16: ; preds = %12
store i32 -1, i32* %4
br label %27
17: ; preds = %15
br label %18
18: ; preds = %17, %11
%19 = load i32, i32* %5
%20 = call i32 @prussdrv_pru_disable(i32 %19)
%21 = load i32, i32* %8
%22 = load i32*, i32** %6
%23 = load i32, i32* %7
%24 = call i32 @prussdrv_pru_write_memory(i32 %21, i32 0, i32* %22, i32 %23)
%25 = load i32, i32* %5
%26 = call i32 @prussdrv_pru_enable(i32 %25)
store i32 0, i32* %4
br label %27
27: ; preds = %18, %16
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @prussdrv_exec_code(i32 %0, i32* %1, i32 %2) {
switch i32 %0, label %10 [
i32 0, label %5
i32 1, label %4
]
4: ; preds = %3
br label %5
5: ; preds = %3, %4
%6 = phi i32 [ 3, %4 ], [ 2, %3 ]
%7 = tail call i32 @prussdrv_pru_disable(i32 %0)
%8 = tail call i32 @prussdrv_pru_write_memory(i32 %6, i32 0, i32* %1, i32 %2)
%9 = tail call i32 @prussdrv_pru_enable(i32 %0)
br label %10
10: ; preds = %3, %5
%11 = phi i32 [ 0, %5 ], [ -1, %3 ]
ret i32 %11
}