#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 *s6_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int EXIT_SUCCESS;
int /*<<< orphan*/ EX_DATAERR;
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ emit_help();
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, int, int, int);
char *strsep(char **, char *);
int main(int argc, char *argv[]) {
  char **ap;
  int ch;
  int ret = 0;
  struct in6_addr v6addr;
  while ((ch = getopt(argc, argv, "h")) != -1) {
    switch (ch) {
    case 'h':
    default:
      emit_help();
    }
  }
  argc -= optind;
  argv += optind;
  if (argc == 0 || *argv == NULL)
    emit_help();
  ap = argv;
  *ap = strsep(argv, "%");
  if ((ret = inet_pton(AF_INET6, *ap, &v6addr)) != 1) {
    if (ret == -1)
      err(EX_OSERR, "system error parsing IPv6 address");
    else
      errx(EX_DATAERR, "could not parse IPv6 address");
  }
  if (v6addr.s6_addr[11] == 255 && v6addr.s6_addr[12] == 254) {
    v6addr.s6_addr[8] ^= 1 << 1;
    printf("%02X-%02X-%02X\n", v6addr.s6_addr[8], v6addr.s6_addr[9],
           v6addr.s6_addr[10]);
  } else {
    exit(1);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11de <main+0x5e>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
jne    11d2 <main+0x52>
jmp    11cd <main+0x4d>
jmp    11d2 <main+0x52>
mov    $0x0,%al
call   1030 <emit_help@plt>
jmp    119d <main+0x1d>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1220 <main+0xa0>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1227 <main+0xa7>
mov    $0x0,%al
call   1030 <emit_help@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x1,%eax
je     12ac <main+0x12c>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1292 <main+0x112>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   1070 <err@plt>
jmp    12a7 <main+0x127>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1040 <errx@plt>
jmp    12ac <main+0x12c>
mov    -0x28(%rbp),%rax
cmpl   $0xff,0x2c(%rax)
jne    1301 <main+0x181>
mov    -0x28(%rbp),%rax
cmpl   $0xfe,0x30(%rax)
jne    1301 <main+0x181>
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%ecx
xor    $0x2,%ecx
mov    %ecx,0x20(%rax)
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x24(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x28(%rax),%ecx
lea    0xd4c(%rip),%rdi
call   1050 <printf@plt>
jmp    130b <main+0x18b>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe6b(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x49>
lea    0xe5a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <emit_help@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
lea    (%r14,%rax,8),%r14
cmp    %ebx,%eax
je     11e1 <main+0x61>
cmpq   $0x0,(%r14)
jne    11e8 <main+0x68>
xor    %eax,%eax
call   1030 <emit_help@plt>
lea    0xe13(%rip),%rsi
mov    %r14,%rdi
call   1080 <strsep@plt>
mov    %rax,(%r14)
mov    0x2dd7(%rip),%rcx
mov    (%rcx),%edi
lea    0x8(%rsp),%rdx
mov    %rax,%rsi
call   1060 <inet_pton@plt>
cmp    $0x1,%eax
je     1246 <main+0xc6>
cmp    $0xffffffff,%eax
jne    1231 <main+0xb1>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1070 <err@plt>
jmp    1246 <main+0xc6>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1040 <errx@plt>
mov    0x8(%rsp),%rax
cmpl   $0xff,0x2c(%rax)
jne    1286 <main+0x106>
cmpl   $0xfe,0x30(%rax)
jne    1286 <main+0x106>
mov    0x20(%rax),%esi
mov    0x24(%rax),%edx
xor    $0x2,%esi
mov    %esi,0x20(%rax)
mov    0x28(%rax),%ecx
lea    0xdd0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@.str = [2 x i8] c"h\00"
@optind = global i64 0
@.str.1 = [2 x i8] c"%\00"
@AF_INET6 = global i32 0
@EX_OSERR = global i32 0
@.str.2 = [34 x i8] c"system error parsing IPv6 address\00"
@EX_DATAERR = global i32 0
@.str.3 = [29 x i8] c"could not parse IPv6 address\00"
@.str.4 = [16 x i8] c"%02X-%02X-%02X\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 i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.in6_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %10
10: ; preds = %20, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %18 [
i32 104, label %17
]
17: ; preds = %15
br label %18
18: ; preds = %15, %17
%19 = call i32 (...) @emit_help()
br label %20
20: ; preds = %18
br label %10
21: ; preds = %10
%22 = load i64, i64* @optind
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = sub nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %4
%27 = load i64, i64* @optind
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
store i8** %29, i8*** %5
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %32, %21
%37 = call i32 (...) @emit_help()
br label %38
38: ; preds = %36, %32
%39 = load i8**, i8*** %5
store i8** %39, i8*** %6
%40 = load i8**, i8*** %5
%41 = call i8* @strsep(i8** %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8**, i8*** %6
store i8* %41, i8** %42
%43 = load i32, i32* @AF_INET6
%44 = load i8**, i8*** %6
%45 = load i8*, i8** %44
%46 = call i32 @inet_pton(i32 %43, i8* %45, %struct.in6_addr* %9)
store i32 %46, i32* %8
%47 = icmp ne i32 %46, 1
br i1 %47, label %48, label %58
48: ; preds = %38
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* @EX_OSERR
%53 = call i32 @err(i32 %52, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %57
54: ; preds = %48
%55 = load i32, i32* @EX_DATAERR
%56 = call i32 @errx(i32 %55, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %54, %51
br label %58
58: ; preds = %57, %38
%59 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%60 = load i32*, i32** %59
%61 = getelementptr inbounds i32, i32* %60, i64 11
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, 255
br i1 %63, label %64, label %89
64: ; preds = %58
%65 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%66 = load i32*, i32** %65
%67 = getelementptr inbounds i32, i32* %66, i64 12
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, 254
br i1 %69, label %70, label %89
70: ; preds = %64
%71 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%72 = load i32*, i32** %71
%73 = getelementptr inbounds i32, i32* %72, i64 8
%74 = load i32, i32* %73
%75 = xor i32 %74, 2
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%77 = load i32*, i32** %76
%78 = getelementptr inbounds i32, i32* %77, i64 8
%79 = load i32, i32* %78
%80 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%81 = load i32*, i32** %80
%82 = getelementptr inbounds i32, i32* %81, i64 9
%83 = load i32, i32* %82
%84 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i32 0, i32 0
%85 = load i32*, i32** %84
%86 = getelementptr inbounds i32, i32* %85, i64 10
%87 = load i32, i32* %86
%88 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %79, i32 %83, i32 %87)
br label %91
89: ; preds = %64, %58
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %70
%92 = load i32, i32* @EXIT_SUCCESS
%93 = call i32 @exit(i32 %92)
unreachable
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
@.str = [2 x i8] c"h\00"
@optind = global i64 0
@.str.1 = [2 x i8] c"%\00"
@AF_INET6 = global i32 0
@EX_OSERR = global i32 0
@.str.2 = [34 x i8] c"system error parsing IPv6 address\00"
@EX_DATAERR = global i32 0
@.str.3 = [29 x i8] c"could not parse IPv6 address\00"
@.str.4 = [16 x i8] c"%02X-%02X-%02X\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.in6_addr
%4 = bitcast %struct.in6_addr* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2, %7
%8 = tail call i32 (...) @emit_help()
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %7
11: ; preds = %7, %2
%12 = load i64, i64* @optind
%13 = trunc i64 %12 to i32
%14 = getelementptr inbounds i8*, i8** %1, i64 %12
%15 = icmp eq i32 %13, %0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i8*, i8** %14
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16, %11
%20 = tail call i32 (...) @emit_help()
br label %21
21: ; preds = %19, %16
%22 = tail call i8* @strsep(i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %14
%23 = load i32, i32* @AF_INET6
%24 = call i32 @inet_pton(i32 %23, i8* %22, %struct.in6_addr* %3)
switch i32 %24, label %28 [
i32 1, label %31
i32 -1, label %25
]
25: ; preds = %21
%26 = load i32, i32* @EX_OSERR
%27 = call i32 @err(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %31
28: ; preds = %21
%29 = load i32, i32* @EX_DATAERR
%30 = call i32 @errx(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %21, %25, %28
%32 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %3, i64 0, i32 0
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 11
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 255
br i1 %36, label %37, label %52
37: ; preds = %31
%38 = getelementptr inbounds i32, i32* %33, i64 12
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, 254
br i1 %40, label %41, label %52
41: ; preds = %37
%42 = getelementptr inbounds i32, i32* %33, i64 8
%43 = load i32, i32* %42
%44 = xor i32 %43, 2
store i32 %44, i32* %42
%45 = getelementptr inbounds i32, i32* %33, i64 9
%46 = load i32, i32* %45
%47 = getelementptr inbounds i32, i32* %33, i64 10
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %46, i32 %48)
%50 = load i32, i32* @EXIT_SUCCESS
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %37, %31
%53 = call i32 @exit(i32 1)
unreachable
}