#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*/ _IOC(int /*<<< orphan*/, float, int /*<<< orphan*/, int);
int /*<<< orphan*/ _IOC_WRITE;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, char const *);
int open(char *, int);
int fpui_open(int flags, const char *regname) {
  int fd = 0;
  int errcd = 0;
  if ((fd = open("/dev/fpi", flags)) < 0) {
    return (fd);
  }
  if ((errcd = ioctl(fd, _IOC(_IOC_WRITE, 'f', 0, sizeof(char *)), regname)) <
      0) {
    close(fd);
    return (errcd);
  }
  return (fd);
}


x86 assembly (clang, -O0):
<fpui_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1183 <fpui_open+0x43>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <fpui_open+0x99>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
movss  0xe66(%rip),%xmm0
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <_IOC@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11d3 <fpui_open+0x93>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <fpui_open+0x99>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fpui_open>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%esi
lea    0xeb4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1193 <fpui_open+0x53>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
movss  0xe94(%rip),%xmm0
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <_IOC@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
jns    1193 <fpui_open+0x53>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/fpi\00"
@_IOC_WRITE = global i32 0
define i32 @fpui_open(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %6
store i32 %12, i32* %3
br label %26
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load i32, i32* @_IOC_WRITE
%16 = call i32 @_IOC(i32 %15, float 1.020000e+02, i32 0, i32 8)
%17 = load i8*, i8** %5
%18 = call i32 @ioctl(i32 %14, i32 %16, i8* %17)
store i32 %18, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %26
24: ; preds = %13
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %20, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/fpi\00"
@_IOC_WRITE = global i32 0
define i32 @fpui_open(i32 %0, i8* %1) {
%3 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i32, i32* @_IOC_WRITE
%7 = tail call i32 @_IOC(i32 %6, float 1.020000e+02, i32 0, i32 8)
%8 = tail call i32 @ioctl(i32 %3, i32 %7, i8* %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @close(i32 %3)
br label %12
12: ; preds = %5, %2, %10
%13 = phi i32 [ %8, %10 ], [ %3, %2 ], [ %3, %5 ]
ret i32 %13
}