#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int tunSetDst(char const *, int /*<<< orphan*/);
int tunSetIp(char const *, int /*<<< orphan*/);
int tunSetMask(char const *, int /*<<< orphan*/);
int tunSetIpMaskDst(const char *dev, uint32_t ip, uint32_t mask, uint32_t dst) {
  int err;
  if ((err = tunSetIp(dev, ip)) < 0) {
    return err;
  }
  if ((err = tunSetMask(dev, mask)) < 0) {
    return err;
  }
  if ((err = tunSetDst(dev, dst)) < 0) {
    return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tunSetIpMaskDst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <tunSetIp@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1168 <tunSetIpMaskDst+0x38>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <tunSetIpMaskDst+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <tunSetMask@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    118b <tunSetIpMaskDst+0x5b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <tunSetIpMaskDst+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <tunSetDst@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11ae <tunSetIpMaskDst+0x7e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <tunSetIpMaskDst+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tunSetIpMaskDst>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rdi,%rbx
call   1050 <tunSetIp@plt>
test   %eax,%eax
js     1165 <tunSetIpMaskDst+0x35>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <tunSetMask@plt>
test   %eax,%eax
js     1165 <tunSetIpMaskDst+0x35>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <tunSetDst@plt>
mov    %eax,%ecx
sar    $0x1f,%eax
and    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tunSetIpMaskDst(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @tunSetIp(i8* %11, i32 %12)
store i32 %13, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i32, i32* %10
store i32 %16, i32* %5
br label %32
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i32, i32* %8
%20 = call i32 @tunSetMask(i8* %18, i32 %19)
store i32 %20, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i32, i32* %10
store i32 %23, i32* %5
br label %32
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = load i32, i32* %9
%27 = call i32 @tunSetDst(i8* %25, i32 %26)
store i32 %27, i32* %10
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %32
31: ; preds = %24
store i32 0, i32* %5
br label %32
32: ; preds = %31, %29, %22, %15
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @tunSetIpMaskDst(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @tunSetIp(i8* %0, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 @tunSetMask(i8* %0, i32 %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @tunSetDst(i8* %0, i32 %3)
%12 = icmp slt i32 %11, 0
%13 = select i1 %12, i32 %11, i32 0
br label %14
14: ; preds = %10, %7, %4
%15 = phi i32 [ %5, %4 ], [ %8, %7 ], [ %13, %10 ]
ret i32 %15
}