#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 uid_t;
typedef int gid_t;

/* Variables and functions */
int /*<<< orphan*/ TUNSETGROUP;
int /*<<< orphan*/ TUNSETOWNER;
scalar_t__ ioctl(int, int /*<<< orphan*/, int const);
int tun_set_owner(int fd, const uid_t *uid, const gid_t *gid) {
  if (uid != NULL) {
    if (*uid != -1 && ioctl(fd, TUNSETOWNER, *uid)) {
      return -1;
    }
  }
  if (gid != NULL) {
    if (*gid != -1 && ioctl(fd, TUNSETGROUP, *gid)) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tun_set_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116d <tun_set_owner+0x5d>
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     1168 <tun_set_owner+0x58>
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     1168 <tun_set_owner+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <tun_set_owner+0xae>
jmp    116d <tun_set_owner+0x5d>
cmpq   $0x0,-0x18(%rbp)
je     11b7 <tun_set_owner+0xa7>
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     11b2 <tun_set_owner+0xa2>
mov    -0x8(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     11b2 <tun_set_owner+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <tun_set_owner+0xae>
jmp    11b7 <tun_set_owner+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tun_set_owner>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %edi,%ebp
test   %rsi,%rsi
je     1141 <tun_set_owner+0x31>
mov    (%rsi),%edx
cmp    $0xffffffff,%edx
je     1141 <tun_set_owner+0x31>
mov    0x2eb5(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116c <tun_set_owner+0x5c>
test   %rbx,%rbx
je     116a <tun_set_owner+0x5a>
mov    (%rbx),%edx
cmp    $0xffffffff,%edx
je     116a <tun_set_owner+0x5a>
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116c <tun_set_owner+0x5c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@TUNSETOWNER = global i32 0
@TUNSETGROUP = global i32 0
define i32 @tun_set_owner(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %6
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32, i32* @TUNSETOWNER
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = call i64 @ioctl(i32 %15, i32 %16, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %4
br label %40
22: ; preds = %14, %10
br label %23
23: ; preds = %22, %3
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i32*, i32** %7
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* %5
%32 = load i32, i32* @TUNSETGROUP
%33 = load i32*, i32** %7
%34 = load i32, i32* %33
%35 = call i64 @ioctl(i32 %31, i32 %32, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 -1, i32* %4
br label %40
38: ; preds = %30, %26
br label %39
39: ; preds = %38, %23
store i32 0, i32* %4
br label %40
40: ; preds = %39, %37, %21
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@TUNSETOWNER = global i32 0
@TUNSETGROUP = global i32 0
define i32 @tun_set_owner(i32 %0, i32* %1, i32* %2) {
%4 = icmp eq i32* %1, null
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = load i32, i32* @TUNSETOWNER
%10 = tail call i64 @ioctl(i32 %0, i32 %9, i32 %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %5, %8, %3
%13 = icmp eq i32* %2, null
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* @TUNSETGROUP
%19 = tail call i64 @ioctl(i32 %0, i32 %18, i32 %15)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14, %17, %12
br label %22
22: ; preds = %17, %8, %21
%23 = phi i32 [ 0, %21 ], [ -1, %8 ], [ -1, %17 ]
ret i32 %23
}