#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 */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int getopt(int, char **, char *);
int inet_aton(char *, struct in_addr *);
int inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
char *optarg;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ yaiv_panic(int, char *);
int /*<<< orphan*/ yaiv_show_usage();
int main(int argc, char **argv) {
  int is_ipv6 = 0;
  char *address = NULL;
  int opts = 0;
  while ((opts = getopt(argc, argv, "46a:h")) != -1) {
    switch (opts) {
    case '4':
      is_ipv6 = 0;
      break;
    case '6':
      is_ipv6 = 1;
      break;
    case 'a':
      address = optarg;
      break;
    case 'h':
      yaiv_show_usage();
      return 0;
      break;
    case '?':
      yaiv_panic(4, NULL);
      break;
    }
  }
  if (address == NULL)
    yaiv_panic(3, NULL);
  int res = 0;
  struct in_addr addr4;
  struct in6_addr addr6;
  if (is_ipv6)
    res = inet_pton(AF_INET6, address, &addr6);
  else
    res = inet_aton(address, &addr4);
  if (res != 1)
    yaiv_panic(is_ipv6 ? 2 : 1, address);
  else {
    fprintf(stdout, "%s is valid %s address\n", address,
            is_ipv6 ? "IPv6" : "IPv4");
    return 0;
  }
  yaiv_panic(255, NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe66(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1254 <main+0xf4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x34,%eax
je     1203 <main+0xa3>
jmp    11bf <main+0x5f>
mov    -0x3c(%rbp),%eax
sub    $0x36,%eax
je     120f <main+0xaf>
jmp    11d0 <main+0x70>
mov    -0x3c(%rbp),%eax
sub    $0x3f,%eax
je     1241 <main+0xe1>
jmp    11e1 <main+0x81>
mov    -0x3c(%rbp),%eax
sub    $0x61,%eax
je     121b <main+0xbb>
jmp    11f2 <main+0x92>
mov    -0x3c(%rbp),%eax
sub    $0x68,%eax
je     122e <main+0xce>
jmp    124f <main+0xef>
movl   $0x0,-0x14(%rbp)
jmp    124f <main+0xef>
movl   $0x1,-0x14(%rbp)
jmp    124f <main+0xef>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    124f <main+0xef>
mov    $0x0,%al
call   1080 <yaiv_show_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1322 <main+0x1c2>
mov    $0x4,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <yaiv_panic@plt>
jmp    118c <main+0x2c>
cmpq   $0x0,-0x20(%rbp)
jne    126d <main+0x10d>
mov    $0x3,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <yaiv_panic@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     129c <main+0x13c>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    %eax,-0x28(%rbp)
jmp    12ac <main+0x14c>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <inet_aton@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     12d7 <main+0x177>
mov    -0x14(%rbp),%ecx
mov    $0x1,%edi
mov    $0x2,%eax
cmp    $0x0,%ecx
cmovne %eax,%edi
mov    -0x20(%rbp),%rsi
call   1030 <yaiv_panic@plt>
jmp    1314 <main+0x1b4>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%esi
lea    0xd35(%rip),%rcx
lea    0xd29(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xd03(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1322 <main+0x1c2>
mov    $0xff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <yaiv_panic@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r12d,%r12d
lea    0xe83(%rip),%r15
mov    0x2e74(%rip),%r13
xor    %r14d,%r14d
jmp    119c <main+0x3c>
nopl   0x0(%rax)
mov    $0x4,%edi
xor    %esi,%esi
call   1030 <yaiv_panic@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x3e,%eax
jle    11c0 <main+0x60>
cmp    $0x3f,%eax
je     1190 <main+0x30>
cmp    $0x61,%eax
je     11d7 <main+0x77>
cmp    $0x68,%eax
jne    119c <main+0x3c>
jmp    11e2 <main+0x82>
nop
cmp    $0xffffffff,%eax
je     11ee <main+0x8e>
cmp    $0x34,%eax
je     11dd <main+0x7d>
cmp    $0x36,%eax
jne    119c <main+0x3c>
mov    $0x1,%r12d
jmp    119c <main+0x3c>
mov    0x0(%r13),%r14
jmp    119c <main+0x3c>
xor    %r12d,%r12d
jmp    119c <main+0x3c>
xor    %eax,%eax
call   1080 <yaiv_show_usage@plt>
jmp    1285 <main+0x125>
test   %r14,%r14
je     1242 <main+0xe2>
test   %r12d,%r12d
je     1253 <main+0xf3>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %r14,%rsi
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
jne    1265 <main+0x105>
test   %r12d,%r12d
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rax
lea    0xdf1(%rip),%rcx
cmove  %rax,%rcx
lea    0xdce(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
jmp    1285 <main+0x125>
mov    $0x3,%edi
xor    %esi,%esi
call   1030 <yaiv_panic@plt>
test   %r12d,%r12d
jne    11f8 <main+0x98>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1060 <inet_aton@plt>
cmp    $0x1,%eax
je     1213 <main+0xb3>
cmp    $0x1,%r12d
mov    $0x2,%edi
sbb    $0x0,%edi
mov    %r14,%rsi
call   1030 <yaiv_panic@plt>
mov    $0xff,%edi
xor    %esi,%esi
call   1030 <yaiv_panic@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.in6_addr = type { i32 }
@.str = [6 x i8] c"46a:h\00"
@optarg = global i8* null
@AF_INET6 = global i32 0
@stdout = global i32 0
@.str.1 = [24 x i8] c"%s is valid %s address\0A\00"
@.str.2 = [5 x i8] c"IPv6\00"
@.str.3 = [5 x i8] c"IPv4\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.in_addr
%11 = alloca %struct.in6_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i32 0, i32* %8
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %8
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32, i32* %8
switch i32 %18, label %27 [
i32 52, label %19
i32 54, label %20
i32 97, label %21
i32 104, label %23
i32 63, label %25
]
19: ; preds = %17
store i32 0, i32* %6
br label %27
20: ; preds = %17
store i32 1, i32* %6
br label %27
21: ; preds = %17
%22 = load i8*, i8** @optarg
store i8* %22, i8** %7
br label %27
23: ; preds = %17
%24 = call i32 (...) @yaiv_show_usage()
store i32 0, i32* %3
br label %63
25: ; preds = %17
%26 = call i32 @yaiv_panic(i32 4, i8* null)
br label %27
27: ; preds = %17, %25, %21, %20, %19
br label %12
28: ; preds = %12
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @yaiv_panic(i32 3, i8* null)
br label %33
33: ; preds = %31, %28
store i32 0, i32* %9
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @AF_INET6
%38 = load i8*, i8** %7
%39 = call i32 @inet_pton(i32 %37, i8* %38, %struct.in6_addr* %11)
store i32 %39, i32* %9
br label %43
40: ; preds = %33
%41 = load i8*, i8** %7
%42 = call i32 @inet_aton(i8* %41, %struct.in_addr* %10)
store i32 %42, i32* %9
br label %43
43: ; preds = %40, %36
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %6
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 2, i32 1
%51 = load i8*, i8** %7
%52 = call i32 @yaiv_panic(i32 %50, i8* %51)
br label %61
53: ; preds = %43
%54 = load i32, i32* @stdout
%55 = load i8*, i8** %7
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
%58 = zext i1 %57 to i64
%59 = select i1 %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%60 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %55, i8* %59)
store i32 0, i32* %3
br label %63
61: ; preds = %46
%62 = call i32 @yaiv_panic(i32 255, i8* null)
br label %63
63: ; preds = %61, %53, %23
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.in6_addr = type { i32 }
@.str = [6 x i8] c"46a:h\00"
@optarg = global i8* null
@AF_INET6 = global i32 0
@stdout = global i32 0
@.str.1 = [24 x i8] c"%s is valid %s address\0A\00"
@.str.2 = [5 x i8] c"IPv6\00"
@.str.3 = [5 x i8] c"IPv4\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.in_addr
%4 = alloca %struct.in6_addr
br label %5
5: ; preds = %14, %2
%6 = phi i32 [ 0, %2 ], [ %15, %14 ]
%7 = phi i8* [ null, %2 ], [ %9, %14 ]
br label %8
8: ; preds = %5, %16
%9 = phi i8* [ %7, %5 ], [ %17, %16 ]
br label %10
10: ; preds = %12, %8
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %12 [
i32 -1, label %22
i32 52, label %14
i32 54, label %13
i32 97, label %16
i32 104, label %18
i32 63, label %20
]
12: ; preds = %10, %20
br label %10
13: ; preds = %10
br label %14
14: ; preds = %10, %13
%15 = phi i32 [ 1, %13 ], [ 0, %10 ]
br label %5
16: ; preds = %10
%17 = load i8*, i8** @optarg
br label %8
18: ; preds = %10
%19 = tail call i32 (...) @yaiv_show_usage()
br label %47
20: ; preds = %10
%21 = tail call i32 @yaiv_panic(i32 4, i8* null)
br label %12
22: ; preds = %10
%23 = icmp eq i8* %9, null
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 @yaiv_panic(i32 3, i8* null)
br label %26
26: ; preds = %24, %22
%27 = bitcast %struct.in_addr* %3 to i8*
%28 = bitcast %struct.in6_addr* %4 to i8*
%29 = icmp eq i32 %6, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* @AF_INET6
%32 = call i32 @inet_pton(i32 %31, i8* %9, %struct.in6_addr* %4)
br label %35
33: ; preds = %26
%34 = call i32 @inet_aton(i8* %9, %struct.in_addr* %3)
br label %35
35: ; preds = %33, %30
%36 = phi i32 [ %32, %30 ], [ %34, %33 ]
%37 = icmp eq i32 %36, 1
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = select i1 %29, i32 1, i32 2
%40 = call i32 @yaiv_panic(i32 %39, i8* %9)
%41 = call i32 @yaiv_panic(i32 255, i8* null)
br label %46
42: ; preds = %35
%43 = load i32, i32* @stdout
%44 = select i1 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %44)
br label %46
46: ; preds = %38, %42
br label %47
47: ; preds = %46, %18
ret i32 0
}