#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ write(int, char *, size_t);
int altremote_set_fpga_config_addr(char *config_addr, size_t len) {
  int fd;
  int ret = 0;
  if (len != 6)
    return -1;
  fd = open("/sys/devices/platform/altremote.0/"
            "fpga_config_addr",
            O_WRONLY);
  if (fd == -1)
    return -1;
  if (write(fd, config_addr, len) != (ssize_t)len)
    ret = -1;
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<altremote_set_fpga_config_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x6,-0x18(%rbp)
je     115e <altremote_set_fpga_config_addr+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <altremote_set_fpga_config_addr+0x8b>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    118c <altremote_set_fpga_config_addr+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <altremote_set_fpga_config_addr+0x8b>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x18(%rbp),%rax
je     11ad <altremote_set_fpga_config_addr+0x7d>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<altremote_set_fpga_config_addr>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x6,%rsi
jne    117f <altremote_set_fpga_config_addr+0x4f>
mov    %rdi,%r14
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     117f <altremote_set_fpga_config_addr+0x4f>
mov    %eax,%ebp
mov    $0x6,%edx
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <write@plt>
xor    %ebx,%ebx
cmp    $0x6,%rax
setne  %bl
neg    %ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"/sys/devices/platform/altremote.0/fpga_config_addr\00"
@O_WRONLY = global i32 0
define i32 @altremote_set_fpga_config_addr(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %7
%8 = load i64, i64* %5
%9 = icmp ne i64 %8, 6
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %29
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 -1, i32* %3
br label %29
17: ; preds = %11
%18 = load i32, i32* %6
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = call i64 @write(i32 %18, i8* %19, i64 %20)
%22 = load i64, i64* %5
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %7
br label %25
25: ; preds = %24, %17
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %16, %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [51 x i8] c"/sys/devices/platform/altremote.0/fpga_config_addr\00"
@O_WRONLY = global i32 0
define i32 @altremote_set_fpga_config_addr(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 6
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i64 @write(i32 %6, i8* %0, i64 6)
%10 = icmp ne i64 %9, 6
%11 = sext i1 %10 to i32
%12 = tail call i32 @close(i32 %6)
br label %13
13: ; preds = %4, %2, %8
%14 = phi i32 [ %11, %8 ], [ -1, %2 ], [ -1, %4 ]
ret i32 %14
}