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

/* Variables and functions */
int is_valid_ip(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *valid_ips[5] = {"192.168.1.1", "1.1.1.1", "0.0.0.0", "192.0.0.1",
                        "255.255.255.255"};
  char *invalid_ips[5] = {"01.1.1.1", "", "1", "...", "256.1.1.1"};
  printf("Valid tests:\n");
  for (int i = 0, size = sizeof(valid_ips) / sizeof(valid_ips[0]); i < size;
       i++)
    printf("%s: %d\n", valid_ips[i], is_valid_ip(valid_ips[i]));
  printf("Invalid tests:\n");
  for (int i = 0, size = sizeof(invalid_ips) / sizeof(invalid_ips[0]); i < size;
       i++)
    printf("%s: %d\n", invalid_ips[i], is_valid_ip(invalid_ips[i]));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xea7(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xe8e(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe66(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x64(%rbp)
movl   $0x5,-0x68(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    1235 <main+0x105>
movslq -0x64(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x78(%rbp)
movslq -0x64(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
call   1050 <is_valid_ip@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11ec <main+0xbc>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x6c(%rbp)
movl   $0x5,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x70(%rbp),%eax
jge    129a <main+0x16a>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rax
mov    %rax,-0x80(%rbp)
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1050 <is_valid_ip@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1251 <main+0x121>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
lea    0xeef(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec3(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe82(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe58(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3e(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3e(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf0(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xded(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd3(%rip),%rbx
mov    %rbx,%rdi
call   1050 <is_valid_ip@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"192.168.1.1\00"
@.str.1 = [8 x i8] c"1.1.1.1\00"
@.str.2 = [8 x i8] c"0.0.0.0\00"
@.str.3 = [10 x i8] c"192.0.0.1\00"
@.str.4 = [16 x i8] c"255.255.255.255\00"
@.str.5 = [9 x i8] c"01.1.1.1\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [2 x i8] c"1\00"
@.str.8 = [4 x i8] c"...\00"
@.str.9 = [10 x i8] c"256.1.1.1\00"
@.str.10 = [14 x i8] c"Valid tests:\0A\00"
@.str.11 = [8 x i8] c"%s: %d\0A\00"
@.str.12 = [16 x i8] c"Invalid tests:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8*]
%3 = alloca [5 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [5 x i8*]* %2 to i8*
%9 = bitcast i8* %8 to [5 x i8*]*
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = bitcast [5 x i8*]* %3 to i8*
%16 = bitcast i8* %15 to [5 x i8*]*
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8** %20
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i32 0, i32 0), i8** %21
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %4
store i32 5, i32* %5
br label %23
23: ; preds = %38, %0
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @is_valid_ip(i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %31, i32 %36)
br label %38
38: ; preds = %27
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %23
41: ; preds = %23
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %6
store i32 5, i32* %7
br label %43
43: ; preds = %58, %41
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %49
%51 = load i8*, i8** %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @is_valid_ip(i8* %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %51, i32 %56)
br label %58
58: ; preds = %47
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %43
61: ; preds = %43
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [12 x i8] c"192.168.1.1\00"
@.str.1 = [8 x i8] c"1.1.1.1\00"
@.str.2 = [8 x i8] c"0.0.0.0\00"
@.str.3 = [10 x i8] c"192.0.0.1\00"
@.str.4 = [16 x i8] c"255.255.255.255\00"
@.str.5 = [9 x i8] c"01.1.1.1\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [2 x i8] c"1\00"
@.str.8 = [4 x i8] c"...\00"
@.str.9 = [10 x i8] c"256.1.1.1\00"
@.str.11 = [8 x i8] c"%s: %d\0A\00"
@str = [13 x i8] c"Valid tests:\00"
@str.13 = [15 x i8] c"Invalid tests:\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.13, i64 0, i64 0))
%13 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32 %15)
%17 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 %17)
%19 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %19)
%21 = tail call i32 @is_valid_ip(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %21)
ret i32 0
}