#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_at(int, size_t);
int /*<<< orphan*/ prussdrv_pru_write_memory(unsigned int, int /*<<< orphan*/,
                                             unsigned int const *, int);
int prussdrv_exec_code_at(int prunum, const unsigned int *code, int codelen,
                          size_t addr) {
  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_at(prunum, addr);
  return 0;
}


x86 assembly (clang, -O0):
<prussdrv_exec_code_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    115c <prussdrv_exec_code_at+0x2c>
movl   $0x2,-0x24(%rbp)
jmp    1183 <prussdrv_exec_code_at+0x53>
cmpl   $0x1,-0x8(%rbp)
jne    1172 <prussdrv_exec_code_at+0x42>
movl   $0x3,-0x24(%rbp)
jmp    117e <prussdrv_exec_code_at+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <prussdrv_exec_code_at+0x7f>
jmp    1183 <prussdrv_exec_code_at+0x53>
mov    -0x8(%rbp),%edi
call   1030 <prussdrv_pru_disable@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <prussdrv_pru_write_memory@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <prussdrv_pru_enable_at@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prussdrv_exec_code_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebp
test   %edi,%edi
je     115c <prussdrv_exec_code_at+0x2c>
mov    $0xffffffff,%ebx
cmp    $0x1,%ebp
jne    1185 <prussdrv_exec_code_at+0x55>
mov    $0x3,%r13d
jmp    1162 <prussdrv_exec_code_at+0x32>
mov    $0x2,%r13d
mov    %ebp,%edi
call   1030 <prussdrv_pru_disable@plt>
xor    %ebx,%ebx
mov    %r13d,%edi
xor    %esi,%esi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1050 <prussdrv_pru_write_memory@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <prussdrv_pru_enable_at@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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