#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_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, size_t);
int altremote_get_fpga_config_addr(char *config_addr, size_t len) {
  int fd;
  if (len != 6)
    return -1;
  fd = open("/sys/devices/platform/altremote.0/"
            "fpga_config_addr",
            O_RDONLY);
  if (fd == -1)
    return -1;
  if (read(fd, config_addr, len) != (ssize_t)len) {
    close(fd);
    return -1;
  }
  config_addr[6] = '\0';
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<altremote_get_fpga_config_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x6,-0x18(%rbp)
je     1157 <altremote_get_fpga_config_addr+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <altremote_get_fpga_config_addr+0x9a>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1185 <altremote_get_fpga_config_addr+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <altremote_get_fpga_config_addr+0x9a>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
cmp    -0x18(%rbp),%rax
je     11b3 <altremote_get_fpga_config_addr+0x83>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <altremote_get_fpga_config_addr+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<altremote_get_fpga_config_addr>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x6,%rsi
jne    1186 <altremote_get_fpga_config_addr+0x56>
mov    %rdi,%r14
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1186 <altremote_get_fpga_config_addr+0x56>
mov    %eax,%ebp
mov    $0x6,%edx
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <read@plt>
mov    $0xffffffff,%ebx
cmp    $0x6,%rax
jne    117f <altremote_get_fpga_config_addr+0x4f>
movb   $0x0,0x6(%r14)
xor    %ebx,%ebx
mov    %ebp,%edi
call   1030 <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_RDONLY = global i32 0
define i32 @altremote_get_fpga_config_addr(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp ne i64 %7, 6
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %31
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %3
br label %31
16: ; preds = %10
%17 = load i32, i32* %6
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i64 @read(i32 %17, i8* %18, i64 %19)
%21 = load i64, i64* %5
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
store i32 -1, i32* %3
br label %31
26: ; preds = %16
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 6
store i8 0, i8* %28
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
store i32 0, i32* %3
br label %31
31: ; preds = %26, %23, %15, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [51 x i8] c"/sys/devices/platform/altremote.0/fpga_config_addr\00"
@O_RDONLY = global i32 0
define i32 @altremote_get_fpga_config_addr(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 6
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = load i32, i32* @O_RDONLY
%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 %16, label %8
8: ; preds = %4
%9 = tail call i64 @read(i32 %6, i8* %0, i64 6)
%10 = icmp eq i64 %9, 6
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 6
store i8 0, i8* %12
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ 0, %11 ], [ -1, %8 ]
%15 = tail call i32 @close(i32 %6)
br label %16
16: ; preds = %13, %4, %2
%17 = phi i32 [ -1, %2 ], [ -1, %4 ], [ %14, %13 ]
ret i32 %17
}