#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*/ juniper_fpga_pack_int(unsigned int, unsigned char *);
int juniper_fpga_partition_write_bytes(int, int, char *, unsigned char *, int);
int juniper_fpga_partition_set_syscall_return(int devNo, int partNo,
                                              unsigned int val) {
  int rv;
  unsigned char buf[5];
  ;
  buf[0] = 0xAA;
  juniper_fpga_pack_int(val, &buf[1]);
  rv = juniper_fpga_partition_write_bytes(devNo, partNo, "accel_syscall_args",
                                          buf, 5);
  if (rv != 0)
    return rv;
  buf[0] = 0x55;
  return juniper_fpga_partition_write_bytes(devNo, partNo, "accel_syscall_args",
                                            buf, 5);
}


x86 assembly (clang, -O0):
<juniper_fpga_partition_set_syscall_return>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movb   $0xaa,-0x19(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x19(%rbp),%rsi
add    $0x1,%rsi
call   1040 <juniper_fpga_pack_int@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x19(%rbp),%rcx
lea    0xeaa(%rip),%rdx
mov    $0x5,%r8d
call   1030 <juniper_fpga_partition_write_bytes@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1179 <juniper_fpga_partition_set_syscall_return+0x59>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <juniper_fpga_partition_set_syscall_return+0x7c>
movb   $0x55,-0x19(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x19(%rbp),%rcx
lea    0xe72(%rip),%rdx
mov    $0x5,%r8d
call   1030 <juniper_fpga_partition_write_bytes@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<juniper_fpga_partition_set_syscall_return>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
movb   $0xaa,0x3(%rsp)
lea    0x4(%rsp),%rsi
mov    %edx,%edi
call   1040 <juniper_fpga_pack_int@plt>
lea    0xec1(%rip),%rdx
lea    0x3(%rsp),%rcx
mov    %ebp,%edi
mov    %ebx,%esi
mov    $0x5,%r8d
call   1030 <juniper_fpga_partition_write_bytes@plt>
test   %eax,%eax
jne    1177 <juniper_fpga_partition_set_syscall_return+0x57>
movb   $0x55,0x3(%rsp)
lea    0xe9d(%rip),%rdx
lea    0x3(%rsp),%rcx
mov    %ebp,%edi
mov    %ebx,%esi
mov    $0x5,%r8d
call   1030 <juniper_fpga_partition_write_bytes@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"accel_syscall_args\00"
define i32 @juniper_fpga_partition_set_syscall_return(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [5 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
store i8 -86, i8* %10
%11 = load i32, i32* %7
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 1
%13 = call i32 @juniper_fpga_pack_int(i32 %11, i8* %12)
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%17 = call i32 @juniper_fpga_partition_write_bytes(i32 %14, i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16, i32 5)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %28
22: ; preds = %3
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
store i8 85, i8* %23
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%27 = call i32 @juniper_fpga_partition_write_bytes(i32 %24, i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %26, i32 5)
store i32 %27, i32* %4
br label %28
28: ; preds = %22, %20
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [19 x i8] c"accel_syscall_args\00"
define i32 @juniper_fpga_partition_set_syscall_return(i32 %0, i32 %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
store i8 -86, i8* %5
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
%7 = call i32 @juniper_fpga_pack_int(i32 %2, i8* %6)
%8 = call i32 @juniper_fpga_partition_write_bytes(i32 %0, i32 %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5, i32 5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
store i8 85, i8* %5
%11 = call i32 @juniper_fpga_partition_write_bytes(i32 %0, i32 %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5, i32 5)
br label %12
12: ; preds = %3, %10
%13 = phi i32 [ %11, %10 ], [ %8, %3 ]
ret i32 %13
}