#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*/ inet_aton(char *, struct in_addr *);
char *strchr(char *, char);
int parse_ip(char *st, unsigned long *ip) {
  char *t;
  t = strchr(st, '.');
  if (!t)
    return 1;
  t = strchr(t + 1, '.');
  if (!t)
    return 1;
  t = strchr(t + 1, '.');
  if (!t)
    return 1;
  if (!inet_aton(st, (struct in_addr *)ip))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<parse_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1159 <parse_ip+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11dc <parse_ip+0xbc>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <parse_ip+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11dc <parse_ip+0xbc>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <parse_ip+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11dc <parse_ip+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <inet_aton@plt>
cmp    $0x0,%eax
jne    11d5 <parse_ip+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    11dc <parse_ip+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     117d <parse_ip+0x5d>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117d <parse_ip+0x5d>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117d <parse_ip+0x5d>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <inet_aton@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i32 @parse_ip(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%7 = load i8*, i8** %4
%8 = call i8* @strchr(i8* %7, i8 signext 46)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 1, i32* %3
br label %34
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i8* @strchr(i8* %14, i8 signext 46)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %12
store i32 1, i32* %3
br label %34
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i8* @strchr(i8* %21, i8 signext 46)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %19
store i32 1, i32* %3
br label %34
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = load i64*, i64** %5
%29 = bitcast i64* %28 to %struct.in_addr*
%30 = call i32 @inet_aton(i8* %27, %struct.in_addr* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26
store i32 1, i32* %3
br label %34
33: ; preds = %26
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %25, %18, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
define i32 @parse_ip(i8* %0, i64* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i8* @strchr(i8* %6, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = bitcast i64* %1 to %struct.in_addr*
%15 = tail call i32 @inet_aton(i8* %0, %struct.in_addr* %14)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %9, %5, %2
%19 = phi i32 [ 1, %2 ], [ 1, %5 ], [ 1, %9 ], [ %17, %13 ]
ret i32 %19
}