#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memmove(char *, char *, int);
int sscanf(char *, char *, int *, int *, int *, int *);
char *strchr(char *, char);
int /*<<< orphan*/ strlcpy(char *, char *, int);
void IP_Scan(char *ipstr, int ip[4]) {
  char *c, buf[64];
  int scan;
  strlcpy(buf, ipstr, sizeof(buf));
  buf[sizeof(buf) - 1] = 0;
  c = strchr(buf, '*');
  while (c) {
    memmove(c + 1, c, c - buf);
    *c++ = '-';
    *c = '1';
    c = strchr(buf, '*');
  }
  scan = sscanf(buf, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]);
  if (scan < 4)
    ip[3] = -1;
  if (scan < 3)
    ip[2] = -1;
  if (scan < 2)
    ip[1] = -1;
  if (scan < 1)
    ip[0] = -1;
}


x86 assembly (clang, -O0):
<IP_Scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x40,%edx
call   1050 <strlcpy@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <IP_Scan+0x91>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
lea    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memmove@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x31,(%rax)
lea    -0x60(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1178 <IP_Scan+0x38>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
mov    -0x10(%rbp),%r8
add    $0x8,%r8
mov    -0x10(%rbp),%r9
add    $0xc,%r9
lea    0xe08(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    1215 <IP_Scan+0xd5>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0xc(%rax)
cmpl   $0x3,-0x64(%rbp)
jge    122a <IP_Scan+0xea>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x8(%rax)
cmpl   $0x2,-0x64(%rbp)
jge    123f <IP_Scan+0xff>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x4(%rax)
cmpl   $0x1,-0x64(%rbp)
jge    1253 <IP_Scan+0x113>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IP_Scan>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r15
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%edx
call   1050 <strlcpy@plt>
movb   $0x0,0x3f(%rsp)
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11ab <IP_Scan+0x6b>
mov    %rax,%rbx
mov    %rsp,%r14
xchg   %ax,%ax
lea    0x1(%rbx),%rdi
mov    %ebx,%edx
sub    %r14d,%edx
mov    %rbx,%rsi
call   1060 <memmove@plt>
movw   $0x312d,(%rbx)
mov    %r14,%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <IP_Scan+0x40>
lea    0x4(%r15),%r14
lea    0x8(%r15),%r12
lea    0xc(%r15),%rbx
lea    0xe42(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
mov    %rbx,%r9
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jg     11fc <IP_Scan+0xbc>
movl   $0xffffffff,(%rbx)
je     11fc <IP_Scan+0xbc>
movl   $0xffffffff,(%r12)
ff
cmp    $0x1,%eax
jg     11fc <IP_Scan+0xbc>
movl   $0xffffffff,(%r14)
je     11fc <IP_Scan+0xbc>
movl   $0xffffffff,(%r15)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define void @IP_Scan(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [64 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strlcpy(i8* %8, i8* %9, i32 64)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 63
store i8 0, i8* %11
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 42)
store i8* %13, i8** %5
br label %14
14: ; preds = %17, %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i32 @memmove(i8* %19, i8* %20, i32 %26)
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 45, i8* %28
%30 = load i8*, i8** %5
store i8 49, i8* %30
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%32 = call i8* @strchr(i8* %31, i8 signext 42)
store i8* %32, i8** %5
br label %14
33: ; preds = %14
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 1
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 2
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 3
%43 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %36, i32* %38, i32* %40, i32* %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 4
br i1 %45, label %46, label %49
46: ; preds = %33
%47 = load i32*, i32** %4
%48 = getelementptr inbounds i32, i32* %47, i64 3
store i32 -1, i32* %48
br label %49
49: ; preds = %46, %33
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 3
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32*, i32** %4
%54 = getelementptr inbounds i32, i32* %53, i64 2
store i32 -1, i32* %54
br label %55
55: ; preds = %52, %49
%56 = load i32, i32* %7
%57 = icmp slt i32 %56, 2
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32*, i32** %4
%60 = getelementptr inbounds i32, i32* %59, i64 1
store i32 -1, i32* %60
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 1
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %4
%66 = getelementptr inbounds i32, i32* %65, i64 0
store i32 -1, i32* %66
br label %67
67: ; preds = %64, %61
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define void @IP_Scan(i8* %0, i32* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlcpy(i8* %4, i8* %0, i32 64)
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 63
store i8 0, i8* %6
%7 = call i8* @strchr(i8* %4, i8 signext 42)
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = ptrtoint [64 x i8]* %3 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i8* [ %7, %9 ], [ %18, %11 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %14, %10
%16 = trunc i64 %15 to i32
%17 = call i32 @memmove(i8* %13, i8* %12, i32 %16)
store i8 45, i8* %12
store i8 49, i8* %13
%18 = call i8* @strchr(i8* %4, i8 signext 42)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %11
20: ; preds = %11, %2
%21 = getelementptr inbounds i32, i32* %1, i64 1
%22 = getelementptr inbounds i32, i32* %1, i64 2
%23 = getelementptr inbounds i32, i32* %1, i64 3
%24 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %21, i32* %22, i32* %23)
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %33
26: ; preds = %20
store i32 -1, i32* %23
%27 = icmp eq i32 %24, 3
br i1 %27, label %33, label %28
28: ; preds = %26
store i32 -1, i32* %22
%29 = icmp slt i32 %24, 2
br i1 %29, label %30, label %33
30: ; preds = %28
store i32 -1, i32* %21
%31 = icmp eq i32 %24, 1
br i1 %31, label %33, label %32
32: ; preds = %30
store i32 -1, i32* %1
br label %33
33: ; preds = %20, %26, %28, %32, %30
ret void
}