#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 */

/* Variables and functions */
scalar_t__ parse_octet(char *, int *, char, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int checkip(char *s) {
  int ip[4];
  if (parse_octet(s, ip, '.', 4, 0, 255, 10)) {
    printf("IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
  } else {
    printf("IP: '%s' - INVALID\n", s);
  }
}


x86 assembly (clang, -O0):
<checkip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x2e,%edx
mov    $0x4,%ecx
xor    %r8d,%r8d
mov    $0xff,%r9d
movl   $0xa,(%rsp)
call   1040 <parse_octet@plt>
cmp    $0x0,%rax
je     117d <checkip+0x5d>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118f <checkip+0x6f>
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkip>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movl   $0xa,(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x2e,%edx
mov    $0x4,%ecx
xor    %r8d,%r8d
mov    $0xff,%r9d
call   1040 <parse_octet@plt>
test   %rax,%rax
je     1172 <checkip+0x52>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1183 <checkip+0x63>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"IP: %d.%d.%d.%d\0A\00"
@.str.1 = [20 x i8] c"IP: '%s' - INVALID\0A\00"
define i32 @checkip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%7 = call i64 @parse_octet(i8* %5, i32* %6, i8 signext 46, i32 4, i32 0, i32 255, i32 10)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13, i32 %15, i32 %17)
br label %22
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [17 x i8] c"IP: %d.%d.%d.%d\0A\00"
@.str.1 = [20 x i8] c"IP: '%s' - INVALID\0A\00"
define i32 @checkip(i8* %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = call i64 @parse_octet(i8* %0, i32* %4, i8 signext 46, i32 4, i32 0, i32 255, i32 10)
%6 = icmp eq i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = load i32, i32* %4
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10, i32 %12, i32 %14)
br label %18
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %7
ret i32 undef
}