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

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *, int *, int *, char *);
ssize_t parse_ipv4prefix(const char *buffer,
                         __attribute__((unused)) const char **error) {
  char c;
  int num, parts[5];
  num = sscanf(buffer, "%d.%d.%d.%d/%d%c", &parts[0], &parts[1], &parts[2],
               &parts[3], &parts[4], &c);
  if (num != 5) {
    return 0;
  }
  for (num = 0; num < 4; num++) {
    if (parts[num] < 0) {
      *error = "Invalid address";
      return 0;
    }
    if (parts[num] > 255) {
      *error = "Invalid address";
      return 0;
    }
  }
  if ((parts[4] < 0) || (parts[4] > 32)) {
    *error = "Invalid prefix length";
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_ipv4prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x40(%rbp),%rcx
add    $0x4,%rcx
lea    -0x40(%rbp),%r8
add    $0x8,%r8
lea    -0x40(%rbp),%r9
add    $0xc,%r9
lea    -0x40(%rbp),%r10
add    $0x10,%r10
lea    0xeb1(%rip),%rsi
lea    -0x19(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x5,-0x20(%rbp)
je     117a <parse_ipv4prefix+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    1228 <parse_ipv4prefix+0x118>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11f3 <parse_ipv4prefix+0xe3>
movslq -0x20(%rbp),%rax
cmpl   $0x0,-0x40(%rbp,%rax,4)
jge    11b4 <parse_ipv4prefix+0xa4>
mov    -0x18(%rbp),%rax
lea    0xe6c(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1228 <parse_ipv4prefix+0x118>
movslq -0x20(%rbp),%rax
cmpl   $0xff,-0x40(%rbp,%rax,4)
jle    11e0 <parse_ipv4prefix+0xd0>
mov    -0x18(%rbp),%rax
lea    0xe40(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1228 <parse_ipv4prefix+0x118>
jmp    11e5 <parse_ipv4prefix+0xd5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1181 <parse_ipv4prefix+0x71>
cmpl   $0x0,-0x30(%rbp)
jl     1207 <parse_ipv4prefix+0xf7>
cmpl   $0x20,-0x30(%rbp)
jle    1221 <parse_ipv4prefix+0x111>
mov    -0x18(%rbp),%rax
lea    0xe0f(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1228 <parse_ipv4prefix+0x118>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ipv4prefix>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x20(%rsp),%rax
lea    0xf(%rsp),%rbx
lea    0xee6(%rip),%rsi
lea    0x10(%rsp),%rdx
push   %rbx
push   %rax
call   1030 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x5,%ecx
jne    1191 <parse_ipv4prefix+0x81>
movdqa 0x10(%rsp),%xmm0
pxor   0xe9f(%rip),%xmm0
pcmpgtd 0xea7(%rip),%xmm0
movmskps %xmm0,%eax
test   %eax,%eax
je     1179 <parse_ipv4prefix+0x69>
lea    0xeba(%rip),%rax
jmp    118c <parse_ipv4prefix+0x7c>
mov    $0x1,%eax
cmpl   $0x21,0x20(%rsp)
jb     1191 <parse_ipv4prefix+0x81>
lea    0xeb5(%rip),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%d.%d.%d.%d/%d%c\00"
@.str.1 = [16 x i8] c"Invalid address\00"
@.str.2 = [22 x i8] c"Invalid prefix length\00"
define i32 @parse_ipv4prefix(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca [5 x i32]
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 0
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 1
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 2
%13 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 3
%14 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 4
%15 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %11, i32* %12, i32* %13, i32* %14, i8* %6)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 5
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %3
br label %54
19: ; preds = %2
store i32 0, i32* %7
br label %20
20: ; preds = %40, %19
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 4
br i1 %22, label %23, label %43
23: ; preds = %20
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = load i8**, i8*** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %30
store i32 0, i32* %3
br label %54
31: ; preds = %23
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %35, 255
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = load i8**, i8*** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %38
store i32 0, i32* %3
br label %54
39: ; preds = %31
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %20
43: ; preds = %20
%44 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 4
%45 = load i32, i32* %44
%46 = icmp slt i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 4
%49 = load i32, i32* %48
%50 = icmp sgt i32 %49, 32
br i1 %50, label %51, label %53
51: ; preds = %47, %43
%52 = load i8**, i8*** %5
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %52
store i32 0, i32* %3
br label %54
53: ; preds = %47
store i32 1, i32* %3
br label %54
54: ; preds = %53, %51, %37, %29, %18
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [17 x i8] c"%d.%d.%d.%d/%d%c\00"
@.str.1 = [16 x i8] c"Invalid address\00"
@.str.2 = [22 x i8] c"Invalid prefix length\00"
define i32 @parse_ipv4prefix(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca i8
%4 = alloca [5 x i32]
%5 = bitcast [5 x i32]* %4 to i8*
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 1
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 2
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 3
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 4
%11 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i8* %3)
%12 = icmp eq i32 %11, 5
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = bitcast [5 x i32]* %4 to <4 x i32>*
%15 = load <4 x i32>, <4 x i32>* %14
%16 = freeze <4 x i32> %15
%17 = icmp ugt <4 x i32> %16, <i32 255, i32 255, i32 255, i32 255>
%18 = bitcast <4 x i1> %17 to i4
%19 = icmp eq i4 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %10
%22 = icmp ugt i32 %21, 32
br i1 %22, label %23, label %25
23: ; preds = %20, %13
%24 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), %20 ]
store i8* %24, i8** %1
br label %25
25: ; preds = %23, %20, %2
%26 = phi i32 [ 0, %2 ], [ 1, %20 ], [ 0, %23 ]
ret i32 %26
}