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

/* Variables and functions */
int /*<<< orphan*/ GPIOHANDLE_REQUEST_INPUT;
int gpiotools_get_values(int, struct gpiohandle_data *);
int gpiotools_release_linehandle(int);
int gpiotools_request_linehandle(char const *, unsigned int *, unsigned int,
                                 int /*<<< orphan*/, struct gpiohandle_data *,
                                 char *);
int gpiotools_gets(const char *device_name, unsigned int *lines,
                   unsigned int nlines, struct gpiohandle_data *data) {
  int fd;
  int ret;
  int ret_close;
  ret = gpiotools_request_linehandle(
      device_name, lines, nlines, GPIOHANDLE_REQUEST_INPUT, data, "gpio-utils");
  if (ret < 0)
    return ret;
  fd = ret;
  ret = gpiotools_get_values(fd, data);
  ret_close = gpiotools_release_linehandle(fd);
  return ret < 0 ? ret : ret_close;
}


x86 assembly (clang, -O0):
<gpiotools_gets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8
lea    0xe9a(%rip),%r9
call   1050 <gpiotools_request_linehandle@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1183 <gpiotools_gets+0x53>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <gpiotools_gets+0x94>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <gpiotools_get_values@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <gpiotools_release_linehandle@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11b8 <gpiotools_gets+0x88>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11be <gpiotools_gets+0x8e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpiotools_gets>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    0x2ea3(%rip),%rax
mov    (%rax),%ecx
lea    0xeba(%rip),%r9
mov    %rbx,%r8
call   1050 <gpiotools_request_linehandle@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116e <gpiotools_gets+0x3e>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <gpiotools_get_values@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <gpiotools_release_linehandle@plt>
mov    %eax,%ebp
test   %ebx,%ebx
cmovs  %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.gpiohandle_data = type { i32 }
@GPIOHANDLE_REQUEST_INPUT = global i32 0
@.str = [11 x i8] c"gpio-utils\00"
define i32 @gpiotools_gets(i8* %0, i32* %1, i32 %2, %struct.gpiohandle_data* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.gpiohandle_data*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store %struct.gpiohandle_data* %3, %struct.gpiohandle_data** %9
%13 = load i8*, i8** %6
%14 = load i32*, i32** %7
%15 = load i32, i32* %8
%16 = load i32, i32* @GPIOHANDLE_REQUEST_INPUT
%17 = load %struct.gpiohandle_data*, %struct.gpiohandle_data** %9
%18 = call i32 @gpiotools_request_linehandle(i8* %13, i32* %14, i32 %15, i32 %16, %struct.gpiohandle_data* %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = load i32, i32* %11
store i32 %22, i32* %5
br label %38
23: ; preds = %4
%24 = load i32, i32* %11
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = load %struct.gpiohandle_data*, %struct.gpiohandle_data** %9
%27 = call i32 @gpiotools_get_values(i32 %25, %struct.gpiohandle_data* %26)
store i32 %27, i32* %11
%28 = load i32, i32* %10
%29 = call i32 @gpiotools_release_linehandle(i32 %28)
store i32 %29, i32* %12
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = load i32, i32* %11
br label %36
34: ; preds = %23
%35 = load i32, i32* %12
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ %33, %32 ], [ %35, %34 ]
store i32 %37, i32* %5
br label %38
38: ; preds = %36, %21
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
%struct.gpiohandle_data = type { i32 }
@GPIOHANDLE_REQUEST_INPUT = global i32 0
@.str = [11 x i8] c"gpio-utils\00"
define i32 @gpiotools_gets(i8* %0, i32* %1, i32 %2, %struct.gpiohandle_data* %3) {
%5 = load i32, i32* @GPIOHANDLE_REQUEST_INPUT
%6 = tail call i32 @gpiotools_request_linehandle(i8* %0, i32* %1, i32 %2, i32 %5, %struct.gpiohandle_data* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i32 @gpiotools_get_values(i32 %6, %struct.gpiohandle_data* %3)
%10 = tail call i32 @gpiotools_release_linehandle(i32 %6)
%11 = icmp slt i32 %9, 0
%12 = select i1 %11, i32 %9, i32 %10
br label %13
13: ; preds = %4, %8
%14 = phi i32 [ %12, %8 ], [ %6, %4 ]
ret i32 %14
}