#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 load_ip_address(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, int *);
char *strchr(char *, char);
int load_ip_prefix(char *data, struct in_addr *addr, int *prefix_len) {
  char *pos;
  pos = strchr(data, '/');
  if (pos == NULL) {
    if (load_ip_address(data, addr) != 1) {
      printf("load_net_address: invalid IP address\n");
      return 0;
    }
    *prefix_len = 32;
  } else {
    *pos = '\0';
    if (load_ip_address(data, addr) != 1) {
      printf("load_ip_prefix: invalid IP address\n");
      return 0;
    }
    pos++;
    if (!(sscanf(pos, "%d", prefix_len) == 1 && *prefix_len >= 0 &&
          *prefix_len <= 32)) {
      printf("load_ip_prefix: invalid network prefix\n");
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<load_ip_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ae <load_ip_prefix+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <load_ip_address@plt>
cmp    $0x1,%eax
je     119f <load_ip_prefix+0x5f>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <load_ip_prefix+0x10a>
mov    -0x20(%rbp),%rax
movl   $0x20,(%rax)
jmp    1243 <load_ip_prefix+0x103>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <load_ip_address@plt>
cmp    $0x1,%eax
je     11e3 <load_ip_prefix+0xa3>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <load_ip_prefix+0x10a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1226 <load_ip_prefix+0xe6>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jl     1226 <load_ip_prefix+0xe6>
mov    -0x20(%rbp),%rax
cmpl   $0x20,(%rax)
jle    123e <load_ip_prefix+0xfe>
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <load_ip_prefix+0x10a>
jmp    1243 <load_ip_prefix+0x103>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ip_prefix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a5 <load_ip_prefix+0x65>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <load_ip_address@plt>
cmp    $0x1,%eax
jne    11c3 <load_ip_prefix+0x83>
add    $0x1,%rbx
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    119c <load_ip_prefix+0x5c>
mov    $0x1,%eax
cmpl   $0x21,(%r14)
jb     11da <load_ip_prefix+0x9a>
lea    0xe60(%rip),%rdi
jmp    11d3 <load_ip_prefix+0x93>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <load_ip_address@plt>
cmp    $0x1,%eax
jne    11cc <load_ip_prefix+0x8c>
movl   $0x20,(%r14)
mov    $0x1,%eax
jmp    11da <load_ip_prefix+0x9a>
lea    0xe60(%rip),%rdi
jmp    11d3 <load_ip_prefix+0x93>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [38 x i8] c"load_net_address: invalid IP address\0A\00"
@.str.1 = [36 x i8] c"load_ip_prefix: invalid IP address\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [40 x i8] c"load_ip_prefix: invalid network prefix\0A\00"
define i32 @load_ip_prefix(i8* %0, %struct.in_addr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.in_addr*
%7 = alloca i32*
%8 = alloca i8*
store i8* %0, i8** %5
store %struct.in_addr* %1, %struct.in_addr** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load %struct.in_addr*, %struct.in_addr** %6
%16 = call i32 @load_ip_address(i8* %14, %struct.in_addr* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %49
20: ; preds = %13
%21 = load i32*, i32** %7
store i32 32, i32* %21
br label %48
22: ; preds = %3
%23 = load i8*, i8** %8
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = load %struct.in_addr*, %struct.in_addr** %6
%26 = call i32 @load_ip_address(i8* %24, %struct.in_addr* %25)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %49
30: ; preds = %22
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i32*, i32** %7
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %45
37: ; preds = %30
%38 = load i32*, i32** %7
%39 = load i32, i32* %38
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32*, i32** %7
%43 = load i32, i32* %42
%44 = icmp sle i32 %43, 32
br i1 %44, label %47, label %45
45: ; preds = %41, %37, %30
%46 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %49
47: ; preds = %41
br label %48
48: ; preds = %47, %20
store i32 1, i32* %4
br label %49
49: ; preds = %48, %45, %28, %18
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str.2 = [3 x i8] c"%d\00"
@str = [39 x i8] c"load_ip_prefix: invalid network prefix\00"
@str.4 = [35 x i8] c"load_ip_prefix: invalid IP address\00"
@str.5 = [37 x i8] c"load_net_address: invalid IP address\00"
define i32 @load_ip_prefix(i8* %0, %struct.in_addr* %1, i32* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i32 @load_ip_address(i8* %0, %struct.in_addr* %1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.5, i64 0, i64 0))
br label %26
11: ; preds = %6
store i32 32, i32* %2
br label %26
12: ; preds = %3
store i8 0, i8* %4
%13 = tail call i32 @load_ip_address(i8* %0, %struct.in_addr* %1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
br label %26
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %4, i64 1
%19 = tail call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %2
%23 = icmp ult i32 %22, 33
br i1 %23, label %26, label %24
24: ; preds = %21, %17
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %11, %21, %24, %15, %9
%27 = phi i32 [ 0, %9 ], [ 0, %15 ], [ 0, %24 ], [ 1, %21 ], [ 1, %11 ]
ret i32 %27
}