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

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int inet_pton4(char const *, struct in_addr *);
int inet_pton6(char const *, struct in6_addr *);
int inet_pton(int af, const char *src, void *dst) {
  switch (af) {
  case AF_INET:
    return inet_pton4(src, (struct in_addr *)dst);
  case AF_INET6:
    return inet_pton6(src, (struct in6_addr *)dst);
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<inet_pton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1171 <inet_pton+0x51>
jmp    1149 <inet_pton+0x29>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
jne    1186 <inet_pton+0x66>
jmp    115c <inet_pton+0x3c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <inet_pton4@plt>
mov    %eax,-0x4(%rbp)
jmp    118d <inet_pton+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <inet_pton6@plt>
mov    %eax,-0x4(%rbp)
jmp    118d <inet_pton+0x6d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_pton>:
cmp    $0x80,%edi
je     113b <inet_pton+0x1b>
cmp    $0x81,%edi
jne    1146 <inet_pton+0x26>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1040 <inet_pton4@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1030 <inet_pton6@plt>
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.in6_addr = type { i32 }
define i32 @inet_pton(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
switch i32 %8, label %19 [
i32 129, label %9
i32 128, label %14
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i8*, i8** %7
%12 = bitcast i8* %11 to %struct.in_addr*
%13 = call i32 @inet_pton4(i8* %10, %struct.in_addr* %12)
store i32 %13, i32* %4
br label %20
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = bitcast i8* %16 to %struct.in6_addr*
%18 = call i32 @inet_pton6(i8* %15, %struct.in6_addr* %17)
store i32 %18, i32* %4
br label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %20
20: ; preds = %19, %14, %9
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.in6_addr = type { i32 }
define i32 @inet_pton(i32 %0, i8* %1, i8* %2) {
switch i32 %0, label %10 [
i32 129, label %4
i32 128, label %7
]
4: ; preds = %3
%5 = bitcast i8* %2 to %struct.in_addr*
%6 = tail call i32 @inet_pton4(i8* %1, %struct.in_addr* %5)
br label %10
7: ; preds = %3
%8 = bitcast i8* %2 to %struct.in6_addr*
%9 = tail call i32 @inet_pton6(i8* %1, %struct.in6_addr* %8)
br label %10
10: ; preds = %3, %7, %4
%11 = phi i32 [ %9, %7 ], [ %6, %4 ], [ -1, %3 ]
ret i32 %11
}