#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 */

/* Variables and functions */
char *do_nofail(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, unsigned int,
                           unsigned int, unsigned int);
int sscanf(char const *, char *, unsigned int *, ...);
int /*<<< orphan*/ strdup(char *);
char *convert_6to4(const char *s) {
  char *new;
  int items;
  unsigned int a, b;
  char c;
  items = sscanf(s, "2002:%x:%x%c", &a, &b, &c);
  if (items <= 0 || items == 2 || (items == 3 && c != ':'))
    return do_nofail((strdup("0.0.0.0")),
                     "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/mrash/psad/refs/heads/"
                     "master/deps/whois/whois.c",
                     1271);
  if (items == 1) {
    items = sscanf(s, "2002:%x:%c", &a, &c);
    if (items != 2 || c != ':')
      return do_nofail((strdup("0.0.0.0")),
                       "/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/mrash/psad/"
                       "refs/heads/master/deps/whois/whois.c",
                       1276);
    b = 0;
  }
  new = do_nofail((malloc(sizeof("255.255.255.255"))),
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/mrash/psad/refs/heads/"
                  "master/deps/whois/whois.c",
                  1280);
  sprintf(new, "%u.%u.%u.%u", a >> 8, a & 0xff, b >> 8, b & 0xff);
  return new;
}


x86 assembly (clang, -O0):
<convert_6to4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x25(%rbp),%r8
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a8 <convert_6to4+0x58>
cmpl   $0x2,-0x1c(%rbp)
je     11a8 <convert_6to4+0x58>
cmpl   $0x3,-0x1c(%rbp)
jne    11d0 <convert_6to4+0x80>
movsbl -0x25(%rbp),%eax
cmp    $0x3a,%eax
je     11d0 <convert_6to4+0x80>
lea    0xe5e(%rip),%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
lea    0xe58(%rip),%rsi
mov    $0x4f7,%edx
call   1050 <do_nofail@plt>
mov    %rax,-0x8(%rbp)
jmp    1298 <convert_6to4+0x148>
cmpl   $0x1,-0x1c(%rbp)
jne    123d <convert_6to4+0xed>
mov    -0x10(%rbp),%rdi
lea    0xeba(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x25(%rbp),%rcx
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    120e <convert_6to4+0xbe>
movsbl -0x25(%rbp),%eax
cmp    $0x3a,%eax
je     1236 <convert_6to4+0xe6>
lea    0xdf8(%rip),%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
lea    0xdf2(%rip),%rsi
mov    $0x4fc,%edx
call   1050 <do_nofail@plt>
mov    %rax,-0x8(%rbp)
jmp    1298 <convert_6to4+0x148>
movl   $0x0,-0x24(%rbp)
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %eax,%edi
lea    0xdc5(%rip),%rsi
mov    $0x500,%edx
call   1050 <do_nofail@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
shr    $0x8,%edx
mov    -0x20(%rbp),%ecx
and    $0xff,%ecx
mov    -0x24(%rbp),%r8d
shr    $0x8,%r8d
mov    -0x24(%rbp),%r9d
and    $0xff,%r9d
lea    0xe1f(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_6to4>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x7(%rsp),%r8
xor    %eax,%eax
call   1040 <sscanf@plt>
test   %eax,%eax
jle    118a <convert_6to4+0x3a>
cmp    $0x2,%eax
je     118a <convert_6to4+0x3a>
cmp    $0x3,%eax
jne    11b5 <convert_6to4+0x65>
cmpb   $0x3a,0x7(%rsp)
je     11b5 <convert_6to4+0x65>
lea    0xe7c(%rip),%rdi
call   1070 <strdup@plt>
lea    0xe78(%rip),%rsi
mov    %eax,%edi
mov    $0x4f7,%edx
call   1050 <do_nofail@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
cmp    $0x1,%eax
jne    11e9 <convert_6to4+0x99>
lea    0xede(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x7(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x2,%eax
jne    1234 <convert_6to4+0xe4>
cmpb   $0x3a,0x7(%rsp)
jne    1234 <convert_6to4+0xe4>
movl   $0x0,0x8(%rsp)
mov    $0x10,%edi
call   1030 <malloc@plt>
lea    0xe1b(%rip),%rsi
mov    %eax,%edi
mov    $0x500,%edx
call   1050 <do_nofail@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
movzbl %dl,%ecx
shr    $0x8,%edx
mov    0x8(%rsp),%r8d
movzbl %r8b,%r9d
shr    $0x8,%r8d
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
call   1060 <sprintf@plt>
jmp    11ac <convert_6to4+0x5c>
lea    0xdd2(%rip),%rdi
call   1070 <strdup@plt>
lea    0xdce(%rip),%rsi
mov    %eax,%edi
mov    $0x4fc,%edx
jmp    11a4 <convert_6to4+0x54>

LLVM IR (-O0):
@.str = [13 x i8] c"2002:%x:%x%c\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mrash/psad/refs/heads/master/deps/whois/whois.c\00"
@.str.3 = [11 x i8] c"2002:%x:%c\00"
@.str.4 = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @convert_6to4(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i8* %8)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %1
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 2
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i8, i8* %8
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 58
br i1 %22, label %23, label %26
23: ; preds = %19, %13, %1
%24 = call i32 @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = call i8* @do_nofail(i32 %24, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1271)
store i8* %25, i8** %2
br label %56
26: ; preds = %19, %16
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %42
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %6, i8* %8)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 2
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 58
br i1 %37, label %38, label %41
38: ; preds = %34, %29
%39 = call i32 @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%40 = call i8* @do_nofail(i32 %39, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1276)
store i8* %40, i8** %2
br label %56
41: ; preds = %34
store i32 0, i32* %7
br label %42
42: ; preds = %41, %26
%43 = call i32 @malloc(i32 16)
%44 = call i8* @do_nofail(i32 %43, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1280)
store i8* %44, i8** %4
%45 = load i8*, i8** %4
%46 = load i32, i32* %6
%47 = lshr i32 %46, 8
%48 = load i32, i32* %6
%49 = and i32 %48, 255
%50 = load i32, i32* %7
%51 = lshr i32 %50, 8
%52 = load i32, i32* %7
%53 = and i32 %52, 255
%54 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %49, i32 %51, i32 %53)
%55 = load i8*, i8** %4
store i8* %55, i8** %2
br label %56
56: ; preds = %42, %38, %23
%57 = load i8*, i8** %2
ret i8* %57
}

LLVM IR (-O2):
@.str = [13 x i8] c"2002:%x:%x%c\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mrash/psad/refs/heads/master/deps/whois/whois.c\00"
@.str.3 = [11 x i8] c"2002:%x:%c\00"
@.str.4 = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @convert_6to4(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i8* %4)
%8 = icmp slt i32 %7, 1
%9 = icmp eq i32 %7, 2
%10 = or i1 %8, %9
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = icmp eq i32 %7, 3
%13 = load i8, i8* %4
%14 = icmp ne i8 %13, 58
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %11, %1
%17 = call i32 @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = call i8* @do_nofail(i32 %17, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1271)
br label %41
19: ; preds = %11
%20 = icmp eq i32 %7, 1
br i1 %20, label %21, label %31
21: ; preds = %19
%22 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %2, i8* %4)
%23 = icmp ne i32 %22, 2
%24 = load i8, i8* %4
%25 = icmp ne i8 %24, 58
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%29 = call i8* @do_nofail(i32 %28, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1276)
br label %41
30: ; preds = %21
store i32 0, i32* %3
br label %31
31: ; preds = %30, %19
%32 = call i32 @malloc(i32 16)
%33 = call i8* @do_nofail(i32 %32, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 1280)
%34 = load i32, i32* %2
%35 = lshr i32 %34, 8
%36 = and i32 %34, 255
%37 = load i32, i32* %3
%38 = lshr i32 %37, 8
%39 = and i32 %37, 255
%40 = call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36, i32 %38, i32 %39)
br label %41
41: ; preds = %31, %27, %16
%42 = phi i8* [ %18, %16 ], [ %29, %27 ], [ %33, %31 ]
ret i8* %42
}