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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bitch(char *, char *);
int inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ isspace(char);
char *skip_white_space(char *);
int extract_ipv4(char **input, char *what, struct in_addr *addr) {
  char *s = *input;
  char c;
  while (isdigit(*s) || *s == '.') {
    s++;
  }
  if (s == *input) {
    bitch("%s is not valid", what);
    return -1;
  }
  if (*s && !isspace(*s) && *s != ';' && *s != ')') {
    bitch("%s is not valid", what);
    return -1;
  }
  c = *s;
  *s = 0;
  if (inet_pton(AF_INET, *input, addr) != 1) {
    *s = c;
    bitch("cannot parse %s", what);
    return -1;
  }
  *s = c;
  *input = skip_white_space(s);
  if (!*input) {
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<extract_ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2a(%rbp)
jne    119d <extract_ipv4+0x4d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
sete   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    11ad <extract_ipv4+0x5d>
jmp    11be <extract_ipv4+0x6e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116f <extract_ipv4+0x1f>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    11eb <extract_ipv4+0x9b>
mov    -0x18(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <extract_ipv4+0x190>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124c <extract_ipv4+0xfc>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    124c <extract_ipv4+0xfc>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     124c <extract_ipv4+0xfc>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     124c <extract_ipv4+0xfc>
mov    -0x18(%rbp),%rsi
lea    0xdc5(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <extract_ipv4+0x190>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     12a3 <extract_ipv4+0x153>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xd7e(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <extract_ipv4+0x190>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <skip_white_space@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12d9 <extract_ipv4+0x189>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <extract_ipv4+0x190>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_ipv4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
jmp    1174 <extract_ipv4+0x24>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <extract_ipv4+0x20>
movzbl (%rbx),%eax
cmp    $0x2e,%al
je     1170 <extract_ipv4+0x20>
cmp    (%r15),%rbx
je     11ac <extract_ipv4+0x5c>
test   %al,%al
je     11b5 <extract_ipv4+0x65>
movsbl %al,%edi
call   1050 <isspace@plt>
mov    (%rbx),%bpl
test   %eax,%eax
jne    11b7 <extract_ipv4+0x67>
cmp    $0x29,%bpl
je     11b7 <extract_ipv4+0x67>
cmp    $0x3b,%bpl
je     11b7 <extract_ipv4+0x67>
lea    0xe4d(%rip),%rdi
jmp    11f3 <extract_ipv4+0xa3>
xor    %ebp,%ebp
movb   $0x0,(%rbx)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rsi
mov    %r12,%rdx
call   1070 <inet_pton@plt>
mov    %bpl,(%rbx)
cmp    $0x1,%eax
jne    11ec <extract_ipv4+0x9c>
mov    %rbx,%rdi
call   1060 <skip_white_space@plt>
mov    %rax,(%r15)
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
jmp    1200 <extract_ipv4+0xb0>
lea    0xe1d(%rip),%rdi
mov    %r14,%rsi
call   1040 <bitch@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [16 x i8] c"%s is not valid\00"
@AF_INET = global i32 0
@.str.1 = [16 x i8] c"cannot parse %s\00"
define i32 @extract_ipv4(i8** %0, i8* %1, %struct.in_addr* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.in_addr*
%8 = alloca i8*
%9 = alloca i8
store i8** %0, i8*** %5
store i8* %1, i8** %6
store %struct.in_addr* %2, %struct.in_addr** %7
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
store i8* %11, i8** %8
br label %12
12: ; preds = %24, %3
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = call i64 @isdigit(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ true, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %8
br label %12
27: ; preds = %22
%28 = load i8*, i8** %8
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = icmp eq i8* %28, %30
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %33)
store i32 -1, i32* %4
br label %84
35: ; preds = %27
%36 = load i8*, i8** %8
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %58
40: ; preds = %35
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = call i32 @isspace(i8 signext %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %58, label %45
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 59
br i1 %49, label %50, label %58
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 41
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i8*, i8** %6
%57 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %56)
store i32 -1, i32* %4
br label %84
58: ; preds = %50, %45, %40, %35
%59 = load i8*, i8** %8
%60 = load i8, i8* %59
store i8 %60, i8* %9
%61 = load i8*, i8** %8
store i8 0, i8* %61
%62 = load i32, i32* @AF_INET
%63 = load i8**, i8*** %5
%64 = load i8*, i8** %63
%65 = load %struct.in_addr*, %struct.in_addr** %7
%66 = call i32 @inet_pton(i32 %62, i8* %64, %struct.in_addr* %65)
%67 = icmp ne i32 %66, 1
br i1 %67, label %68, label %73
68: ; preds = %58
%69 = load i8, i8* %9
%70 = load i8*, i8** %8
store i8 %69, i8* %70
%71 = load i8*, i8** %6
%72 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %71)
store i32 -1, i32* %4
br label %84
73: ; preds = %58
%74 = load i8, i8* %9
%75 = load i8*, i8** %8
store i8 %74, i8* %75
%76 = load i8*, i8** %8
%77 = call i8* @skip_white_space(i8* %76)
%78 = load i8**, i8*** %5
store i8* %77, i8** %78
%79 = load i8**, i8*** %5
%80 = load i8*, i8** %79
%81 = icmp ne i8* %80, null
br i1 %81, label %83, label %82
82: ; preds = %73
store i32 -1, i32* %4
br label %84
83: ; preds = %73
store i32 1, i32* %4
br label %84
84: ; preds = %83, %82, %68, %55, %32
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [16 x i8] c"%s is not valid\00"
@AF_INET = global i32 0
@.str.1 = [16 x i8] c"cannot parse %s\00"
define i32 @extract_ipv4(i8** nocapture %0, i8* %1, %struct.in_addr* %2) {
%4 = load i8*, i8** %0
br label %5
5: ; preds = %13, %3
%6 = phi i8* [ %4, %3 ], [ %14, %13 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %15
13: ; preds = %5, %10
%14 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
15: ; preds = %10
%16 = load i8*, i8** %0
%17 = icmp eq i8* %6, %16
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %41
20: ; preds = %15
%21 = icmp eq i8 %11, 0
br i1 %21, label %29, label %22
22: ; preds = %20
%23 = tail call i32 @isspace(i8 signext %11)
%24 = icmp eq i32 %23, 0
%25 = load i8, i8* %6
br i1 %24, label %26, label %29
26: ; preds = %22
switch i8 %25, label %27 [
i8 59, label %29
i8 41, label %29
]
27: ; preds = %26
%28 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %41
29: ; preds = %22, %26, %26, %20
%30 = phi i8 [ %25, %26 ], [ %25, %26 ], [ 0, %20 ], [ %25, %22 ]
store i8 0, i8* %6
%31 = load i32, i32* @AF_INET
%32 = load i8*, i8** %0
%33 = tail call i32 @inet_pton(i32 %31, i8* %32, %struct.in_addr* %2)
%34 = icmp eq i32 %33, 1
store i8 %30, i8* %6
br i1 %34, label %37, label %35
35: ; preds = %29
%36 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %41
37: ; preds = %29
%38 = tail call i8* @skip_white_space(i8* %6)
store i8* %38, i8** %0
%39 = icmp eq i8* %38, null
%40 = select i1 %39, i32 -1, i32 1
br label %41
41: ; preds = %37, %35, %27, %18
%42 = phi i32 [ -1, %18 ], [ -1, %35 ], [ -1, %27 ], [ %40, %37 ]
ret i32 %42
}