#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 in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int get_if_addr(char const *, struct in_addr *);
int inet_pton(int /*<<< orphan*/, char const *, struct in_addr *);
int inet_if_addr(const char *str, struct in_addr *if_addr) {
  int ret;
  ret = inet_pton(AF_INET, str, if_addr);
  if (ret == 1) {
    return 0;
  }
  ret = get_if_addr(str, if_addr);
  if (ret == 0) {
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<inet_if_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    115f <inet_if_addr+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    118c <inet_if_addr+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <get_if_addr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1185 <inet_if_addr+0x65>
movl   $0x0,-0x4(%rbp)
jmp    118c <inet_if_addr+0x6c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_if_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <inet_pton@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
je     1156 <inet_if_addr+0x36>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <get_if_addr@plt>
neg    %eax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define i32 @inet_if_addr(i8* %0, %struct.in_addr* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.in_addr*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.in_addr* %1, %struct.in_addr** %5
%7 = load i32, i32* @AF_INET
%8 = load i8*, i8** %4
%9 = load %struct.in_addr*, %struct.in_addr** %5
%10 = call i32 @inet_pton(i32 %7, i8* %8, %struct.in_addr* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %22
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load %struct.in_addr*, %struct.in_addr** %5
%17 = call i32 @get_if_addr(i8* %15, %struct.in_addr* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 0, i32* %3
br label %22
21: ; preds = %14
store i32 -1, i32* %3
br label %22
22: ; preds = %21, %20, %13
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define i32 @inet_if_addr(i8* %0, %struct.in_addr* %1) {
%3 = load i32, i32* @AF_INET
%4 = tail call i32 @inet_pton(i32 %3, i8* %0, %struct.in_addr* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @get_if_addr(i8* %0, %struct.in_addr* %1)
%8 = icmp ne i32 %7, 0
%9 = sext i1 %8 to i32
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ 0, %2 ], [ %9, %6 ]
ret i32 %11
}