#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 int /*<<< orphan*/ vals;
struct gpiohandle_data {
  int *values;
};

/* Variables and functions */
int /*<<< orphan*/ GPIOHANDLE_GET_LINE_VALUES_IOCTL;
int errno;
int ioctl(int, int /*<<< orphan*/, struct gpiohandle_data *);
int /*<<< orphan*/ memset(struct gpiohandle_data *, int /*<<< orphan*/, int);
int get_value_v1(int lfd) {
  struct gpiohandle_data vals;
  int ret;
  memset(&vals, 0, sizeof(vals));
  ret = ioctl(lfd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &vals);
  if (ret == -1)
    return -errno;
  return vals.values[0];
}


x86 assembly (clang, -O0):
<get_value_v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1170 <get_value_v1+0x50>
xor    %eax,%eax
mov    0x2e72(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <get_value_v1+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_value_v1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1161 <get_value_v1+0x41>
mov    0x8(%rsp),%rax
mov    (%rax),%ebx
jmp    116a <get_value_v1+0x4a>
mov    0x2e70(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.gpiohandle_data = type { i32* }
@GPIOHANDLE_GET_LINE_VALUES_IOCTL = global i32 0
@errno = global i32 0
define i32 @get_value_v1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.gpiohandle_data
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 @memset(%struct.gpiohandle_data* %4, i32 0, i32 8)
%7 = load i32, i32* %3
%8 = load i32, i32* @GPIOHANDLE_GET_LINE_VALUES_IOCTL
%9 = call i32 @ioctl(i32 %7, i32 %8, %struct.gpiohandle_data* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
store i32 %14, i32* %2
br label %20
15: ; preds = %1
%16 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %4, i32 0, i32 0
%17 = load i32*, i32** %16
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
store i32 %19, i32* %2
br label %20
20: ; preds = %15, %12
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.gpiohandle_data = type { i32* }
@GPIOHANDLE_GET_LINE_VALUES_IOCTL = global i32 0
@errno = global i32 0
define i32 @get_value_v1(i32 %0) {
%2 = alloca %struct.gpiohandle_data
%3 = bitcast %struct.gpiohandle_data* %2 to i8*
%4 = call i32 @memset(%struct.gpiohandle_data* %2, i32 0, i32 8)
%5 = load i32, i32* @GPIOHANDLE_GET_LINE_VALUES_IOCTL
%6 = call i32 @ioctl(i32 %0, i32 %5, %struct.gpiohandle_data* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
br label %15
11: ; preds = %1
%12 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %2, i64 0, i32 0
%13 = load i32*, i32** %12
%14 = load i32, i32* %13
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ %10, %8 ], [ %14, %11 ]
ret i32 %16
}