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

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int INET6_ADDRSTRLEN;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *inet_ntop(int, unsigned char *, char *, int);
int inet_pton(int, char *, unsigned char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  unsigned char buf[sizeof(struct in6_addr)];
  int domain, s;
  char str[INET6_ADDRSTRLEN];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s {i4|i6|<num>} string\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  domain = (strcmp(argv[1], "i4") == 0)   ? AF_INET
           : (strcmp(argv[1], "i6") == 0) ? AF_INET6
                                          : atoi(argv[1]);
  printf("domain is %d\n", domain);
  s = inet_pton(domain, argv[2], buf);
  if (s <= 0) {
    if (s == 0)
      fprintf(stderr, "Not in presentation format\n");
    else
      perror("inet_pton");
    exit(EXIT_FAILURE);
  }
  if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
    perror("inet_ntop");
    exit(EXIT_FAILURE);
  }
  printf("%s\n", str);
  exit(EXIT_SUCCESS);
}


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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f8 <main+0x78>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe19(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1227 <main+0xa7>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    126c <main+0xec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xded(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1256 <main+0xd6>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    1266 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     12e4 <main+0x164>
cmpl   $0x0,-0x1c(%rbp)
jne    12ca <main+0x14a>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12d6 <main+0x156>
lea    0xd7f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    0x2cf2(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1321 <main+0x1a1>
lea    0xd4c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rsi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    0x2e3f(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%edi
jne    11e4 <main+0x54>
mov    0x8(%r14),%rdi
lea    0xe52(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1203 <main+0x73>
mov    0x2e01(%rip),%rax
mov    (%rax),%r15d
jmp    1230 <main+0xa0>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe09(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1284 <main+0xf4>
mov    0x8(%r14),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1224 <main+0x94>
mov    0x2db9(%rip),%rax
mov    (%rax),%r15d
jmp    1230 <main+0xa0>
mov    0x8(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
lea    0xdef(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rsi
lea    -0x24(%rbp),%rdx
mov    %r15d,%edi
call   1080 <inet_pton@plt>
test   %eax,%eax
jg     1260 <main+0xd0>
je     12a8 <main+0x118>
lea    0xdf2(%rip),%rdi
jmp    127f <main+0xef>
mov    (%r12),%ecx
lea    -0x24(%rbp),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
jne    1292 <main+0x102>
lea    0xddb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1284 <main+0xf4>

LLVM IR (-O0):
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s {i4|i6|<num>} string\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"i4\00"
@AF_INET = global i32 0
@.str.2 = [3 x i8] c"i6\00"
@AF_INET6 = global i32 0
@.str.3 = [14 x i8] c"domain is %d\0A\00"
@.str.4 = [28 x i8] c"Not in presentation format\0A\00"
@.str.5 = [10 x i8] c"inet_pton\00"
@.str.6 = [10 x i8] c"inet_ntop\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @INET6_ADDRSTRLEN
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = load i32, i32* @AF_INET
br label %48
33: ; preds = %25
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = load i32, i32* @AF_INET6
br label %46
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
br label %46
46: ; preds = %41, %39
%47 = phi i32 [ %40, %39 ], [ %45, %41 ]
br label %48
48: ; preds = %46, %31
%49 = phi i32 [ %32, %31 ], [ %47, %46 ]
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %7
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%57 = call i32 @inet_pton(i32 %52, i8* %55, i8* %56)
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp sle i32 %58, 0
br i1 %59, label %60, label %71
60: ; preds = %48
%61 = load i32, i32* %8
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %68
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %48
%72 = load i32, i32* %7
%73 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%74 = load i32, i32* @INET6_ADDRSTRLEN
%75 = call i32* @inet_ntop(i32 %72, i8* %73, i8* %14, i32 %74)
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %81
77: ; preds = %71
%78 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %71
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %14)
%83 = load i32, i32* @EXIT_SUCCESS
%84 = call i32 @exit(i32 %83)
unreachable
}

LLVM IR (-O2):
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s {i4|i6|<num>} string\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"i4\00"
@AF_INET = global i32 0
@.str.2 = [3 x i8] c"i6\00"
@AF_INET6 = global i32 0
@.str.3 = [14 x i8] c"domain is %d\0A\00"
@.str.4 = [28 x i8] c"Not in presentation format\0A\00"
@.str.5 = [10 x i8] c"inet_pton\00"
@.str.6 = [10 x i8] c"inet_ntop\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @INET6_ADDRSTRLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp eq i32 %0, 3
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* @AF_INET
br label %31
22: ; preds = %15
%23 = load i8*, i8** %16
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32, i32* @AF_INET6
br label %31
28: ; preds = %22
%29 = load i8*, i8** %16
%30 = tail call i32 @atoi(i8* %29)
br label %31
31: ; preds = %26, %28, %20
%32 = phi i32 [ %21, %20 ], [ %27, %26 ], [ %30, %28 ]
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @inet_pton(i32 %32, i8* %35, i8* %4)
%37 = icmp slt i32 %36, 1
br i1 %37, label %38, label %48
38: ; preds = %31
%39 = icmp eq i32 %36, 0
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %45
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %31
%49 = load i32, i32* @INET6_ADDRSTRLEN
%50 = call i32* @inet_ntop(i32 %32, i8* %4, i8* %7, i32 %49)
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = call i32 @puts(i8* %7)
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @exit(i32 %58)
unreachable
}