void smart_gpio_request(int gpio_num, char *gpio_name, int *ret) {
  int local_ret;
  if ((*ret != 0) || (gpio_num == -1)) {
    return;
  }
  local_ret = gpio_request(gpio_num, gpio_name);
  if (local_ret < 0) {
    pr_err("%s: gpio_request %d return"
           "err: %d.\n",
           __func__, gpio_num, local_ret);
    *ret = local_ret;
  }
}


x86 assembly (clang, -O0):
<smart_gpio_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    114a <smart_gpio_request+0x2a>
cmpl   $0xffffffff,-0x4(%rbp)
jne    114f <smart_gpio_request+0x2f>
jmp    118e <smart_gpio_request+0x6e>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1030 <gpio_request@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    118e <smart_gpio_request+0x6e>
mov    -0x4(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe89(%rip),%rdi
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1040 <pr_err@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smart_gpio_request>:
push   %rbp
push   %r14
push   %rbx
cmp    $0xffffffff,%edi
je     115c <smart_gpio_request+0x3c>
mov    %rdx,%r14
cmpl   $0x0,(%rdx)
jne    115c <smart_gpio_request+0x3c>
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <gpio_request@plt>
test   %eax,%eax
jns    115c <smart_gpio_request+0x3c>
mov    %eax,%ebx
lea    0xeb9(%rip),%rdi
lea    0xed6(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <pr_err@plt>
mov    %ebx,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"%s: gpio_request %d returnerr: %d.\0A\00"
@__func__.smart_gpio_request = [19 x i8] c"smart_gpio_request\00"
define void @smart_gpio_request(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
%9 = load i32, i32* %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %11, %3
br label %27
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @gpio_request to i32 (i32, i8*, ...)*)(i32 %16, i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i32, i32* %4
%23 = load i32, i32* %7
%24 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @pr_err to i32 (i8*, i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__func__.smart_gpio_request, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %7
%26 = load i32*, i32** %6
store i32 %25, i32* %26
br label %27
27: ; preds = %14, %21, %15
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"%s: gpio_request %d returnerr: %d.\0A\00"
@__func__.smart_gpio_request = [19 x i8] c"smart_gpio_request\00"
define void @smart_gpio_request(i32 %0, i8* %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
%6 = icmp eq i32 %0, -1
%7 = or i1 %6, %5
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @gpio_request to i32 (i32, i8*, ...)*)(i32 %0, i8* %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @pr_err to i32 (i8*, i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__func__.smart_gpio_request, i64 0, i64 0), i32 %0, i32 %9)
store i32 %9, i32* %2
br label %13
13: ; preds = %8, %11, %3
ret void
}