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


x86 assembly (clang, -O0):
<smart_gpio_direction_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1149 <smart_gpio_direction_output+0x29>
cmpl   $0xffffffff,-0x4(%rbp)
jne    114e <smart_gpio_direction_output+0x2e>
jmp    118c <smart_gpio_direction_output+0x6c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1030 <gpio_direction_output@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118c <smart_gpio_direction_output+0x6c>
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe8b(%rip),%rdi
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1040 <pr_err@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smart_gpio_direction_output>:
push   %rbp
push   %r14
push   %rbx
cmp    $0xffffffff,%edi
je     115c <smart_gpio_direction_output+0x3c>
mov    %rdx,%r14
cmpl   $0x0,(%rdx)
jne    115c <smart_gpio_direction_output+0x3c>
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <gpio_direction_output@plt>
test   %eax,%eax
jns    115c <smart_gpio_direction_output+0x3c>
mov    %eax,%ebx
lea    0xeb9(%rip),%rdi
lea    0xedf(%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 = [45 x i8] c"%s: gpio_direction_output %d returnerr: %d.\0A\00"
@__func__.smart_gpio_direction_output = [28 x i8] c"smart_gpio_direction_output\00"
define void @smart_gpio_direction_output(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %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 i32, i32* %5
%18 = call i32 (i32, i32, ...) bitcast (i32 (...)* @gpio_direction_output to i32 (i32, i32, ...)*)(i32 %16, i32 %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 ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @__func__.smart_gpio_direction_output, 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 = [45 x i8] c"%s: gpio_direction_output %d returnerr: %d.\0A\00"
@__func__.smart_gpio_direction_output = [28 x i8] c"smart_gpio_direction_output\00"
define void @smart_gpio_direction_output(i32 %0, i32 %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, i32, ...) bitcast (i32 (...)* @gpio_direction_output to i32 (i32, i32, ...)*)(i32 %0, i32 %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 ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @__func__.smart_gpio_direction_output, i64 0, i64 0), i32 %0, i32 %9)
store i32 %9, i32* %2
br label %13
13: ; preds = %8, %11, %3
ret void
}