#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 uint32_t;
struct gpiohandle_request {
  int lines;
  unsigned int *lineoffsets;
  int flags;
  unsigned int *default_values;
  int fd;
  int /*<<< orphan*/ consumer_label;
};
typedef int /*<<< orphan*/ req;

/* Variables and functions */
int GPIOHANDLE_REQUEST_OUTPUT;
int /*<<< orphan*/ GPIO_GET_LINEHANDLE_IOCTL;
int errno;
int ioctl(int, int /*<<< orphan*/, struct gpiohandle_request *);
int /*<<< orphan*/ memset(struct gpiohandle_request *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int request_line_v1(int cfd, unsigned int offset, uint32_t flags,
                    unsigned int val) {
  struct gpiohandle_request req;
  int ret;
  memset(&req, 0, sizeof(req));
  req.lines = 1;
  req.lineoffsets[0] = offset;
  req.flags = flags;
  strcpy(req.consumer_label, "gpio-mockup-cdev");
  if (flags & GPIOHANDLE_REQUEST_OUTPUT)
    req.default_values[0] = val;
  ret = ioctl(cfd, GPIO_GET_LINEHANDLE_IOCTL, &req);
  if (ret == -1)
    return -errno;
  return req.fd;
}


x86 assembly (clang, -O0):
<request_line_v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x1,-0x40(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
lea    0xe8c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%eax
mov    0x2e65(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1197 <request_line_v1+0x67>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    11cc <request_line_v1+0x9c>
xor    %eax,%eax
mov    0x2e0e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <request_line_v1+0xa2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_line_v1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r15d
lea    0x8(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x1,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    %ebp,0x18(%rsp)
mov    0x2c(%rsp),%edi
lea    0xe88(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e64(%rip),%rax
test   %ebp,(%rax)
je     1190 <request_line_v1+0x60>
mov    0x20(%rsp),%rax
mov    %r14d,(%rax)
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11b2 <request_line_v1+0x82>
mov    0x28(%rsp),%r12d
jmp    11bc <request_line_v1+0x8c>
mov    0x2e17(%rip),%rax
sub    (%rax),%r12d
mov    %r12d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gpiohandle_request = type { i32, i32*, i32, i32*, i32, i32 }
@.str = [17 x i8] c"gpio-mockup-cdev\00"
@GPIOHANDLE_REQUEST_OUTPUT = global i32 0
@GPIO_GET_LINEHANDLE_IOCTL = global i32 0
@errno = global i32 0
define i32 @request_line_v1(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.gpiohandle_request
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = call i32 @memset(%struct.gpiohandle_request* %10, i32 0, i32 40)
%13 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 0
store i32 1, i32* %13
%14 = load i32, i32* %7
%15 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 1
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 0
store i32 %14, i32* %17
%18 = load i32, i32* %8
%19 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 5
%21 = load i32, i32* %20
%22 = call i32 @strcpy(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %8
%24 = load i32, i32* @GPIOHANDLE_REQUEST_OUTPUT
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %4
%28 = load i32, i32* %9
%29 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 3
%30 = load i32*, i32** %29
%31 = getelementptr inbounds i32, i32* %30, i64 0
store i32 %28, i32* %31
br label %32
32: ; preds = %27, %4
%33 = load i32, i32* %6
%34 = load i32, i32* @GPIO_GET_LINEHANDLE_IOCTL
%35 = call i32 @ioctl(i32 %33, i32 %34, %struct.gpiohandle_request* %10)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i32, i32* @errno
%40 = sub nsw i32 0, %39
store i32 %40, i32* %5
br label %44
41: ; preds = %32
%42 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %10, i32 0, i32 4
%43 = load i32, i32* %42
store i32 %43, i32* %5
br label %44
44: ; preds = %41, %38
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
%struct.gpiohandle_request = type { i32, i32*, i32, i32*, i32, i32 }
@.str = [17 x i8] c"gpio-mockup-cdev\00"
@GPIOHANDLE_REQUEST_OUTPUT = global i32 0
@GPIO_GET_LINEHANDLE_IOCTL = global i32 0
@errno = global i32 0
define i32 @request_line_v1(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.gpiohandle_request
%6 = bitcast %struct.gpiohandle_request* %5 to i8*
%7 = call i32 @memset(%struct.gpiohandle_request* %5, i32 0, i32 40)
%8 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 0
store i32 1, i32* %8
%9 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 1
%10 = load i32*, i32** %9
store i32 %1, i32* %10
%11 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 2
store i32 %2, i32* %11
%12 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 5
%13 = load i32, i32* %12
%14 = call i32 @strcpy(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @GPIOHANDLE_REQUEST_OUTPUT
%16 = and i32 %15, %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %4
%19 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 3
%20 = load i32*, i32** %19
store i32 %3, i32* %20
br label %21
21: ; preds = %18, %4
%22 = load i32, i32* @GPIO_GET_LINEHANDLE_IOCTL
%23 = call i32 @ioctl(i32 %0, i32 %22, %struct.gpiohandle_request* %5)
%24 = icmp eq i32 %23, -1
%25 = load i32, i32* @errno
%26 = sub nsw i32 0, %25
%27 = getelementptr inbounds %struct.gpiohandle_request, %struct.gpiohandle_request* %5, i64 0, i32 4
%28 = load i32, i32* %27
%29 = select i1 %24, i32 %26, i32 %28
ret i32 %29
}