#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 */
char *strsep(char **, char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int parse_ip(char *line, unsigned int *out) {
  char *s1, *s2, *s3, *s4;
  if ((s1 = strsep(&line, ".")) == NULL)
    return 0;
  if ((s2 = strsep(&line, ".")) == NULL)
    return 0;
  if ((s3 = strsep(&line, ".")) == NULL)
    return 0;
  if ((s4 = strsep(&line, ".")) == NULL)
    return 0;
  unsigned int i1, i2, i3, i4;
  if ((i1 = strtoul(s1, NULL, 10)) >= 256)
    return 0;
  if ((i2 = strtoul(s2, NULL, 10)) >= 256)
    return 0;
  if ((i3 = strtoul(s3, NULL, 10)) >= 256)
    return 0;
  if ((i4 = strtoul(s4, NULL, 10)) >= 256)
    return 0;
  *out = (i1 << 24) | (i2 << 16) | (i3 << 8) | i4;
  return 1;
}


x86 assembly (clang, -O0):
<parse_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    115a <parse_ip+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
lea    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1184 <parse_ip+0x64>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
lea    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ae <parse_ip+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
lea    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11d8 <parse_ip+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x100,%eax
jb     1204 <parse_ip+0xe4>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x100,%eax
jb     1230 <parse_ip+0x110>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x100,%eax
jb     125c <parse_ip+0x13c>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x100,%eax
jb     1288 <parse_ip+0x168>
movl   $0x0,-0x4(%rbp)
jmp    12ae <parse_ip+0x18e>
mov    -0x3c(%rbp),%ecx
shl    $0x18,%ecx
mov    -0x40(%rbp),%eax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x44(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
or     -0x48(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,(%rsp)
lea    0xec7(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strsep@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1224 <parse_ip+0x104>
mov    %rax,%rbp
lea    0xeaa(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1224 <parse_ip+0x104>
mov    %rax,%r12
lea    0xe8f(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1224 <parse_ip+0x104>
mov    %rax,%r13
lea    0xe74(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1224 <parse_ip+0x104>
mov    %rax,%r15
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmp    $0xff,%eax
ja     1224 <parse_ip+0x104>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmp    $0xff,%eax
ja     1224 <parse_ip+0x104>
mov    %eax,%r12d
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmp    $0xff,%eax
ja     1224 <parse_ip+0x104>
mov    %eax,%r13d
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmp    $0xff,%eax
ja     1224 <parse_ip+0x104>
shl    $0x18,%ebp
shl    $0x10,%r12d
or     %ebp,%r12d
shl    $0x8,%r13d
or     %r12d,%r13d
or     %eax,%r13d
mov    %r13d,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @parse_ip(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%14 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %3
br label %61
17: ; preds = %2
%18 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %7
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %3
br label %61
21: ; preds = %17
%22 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %3
br label %61
25: ; preds = %21
%26 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %3
br label %61
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @strtoul(i8* %30, i32* null, i32 10)
store i32 %31, i32* %10
%32 = icmp uge i32 %31, 256
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %3
br label %61
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = call i32 @strtoul(i8* %35, i32* null, i32 10)
store i32 %36, i32* %11
%37 = icmp uge i32 %36, 256
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 0, i32* %3
br label %61
39: ; preds = %34
%40 = load i8*, i8** %8
%41 = call i32 @strtoul(i8* %40, i32* null, i32 10)
store i32 %41, i32* %12
%42 = icmp uge i32 %41, 256
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 0, i32* %3
br label %61
44: ; preds = %39
%45 = load i8*, i8** %9
%46 = call i32 @strtoul(i8* %45, i32* null, i32 10)
store i32 %46, i32* %13
%47 = icmp uge i32 %46, 256
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 0, i32* %3
br label %61
49: ; preds = %44
%50 = load i32, i32* %10
%51 = shl i32 %50, 24
%52 = load i32, i32* %11
%53 = shl i32 %52, 16
%54 = or i32 %51, %53
%55 = load i32, i32* %12
%56 = shl i32 %55, 8
%57 = or i32 %54, %56
%58 = load i32, i32* %13
%59 = or i32 %57, %58
%60 = load i32*, i32** %5
store i32 %59, i32* %60
store i32 1, i32* %3
br label %61
61: ; preds = %49, %48, %43, %38, %33, %28, %24, %20, %16
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @parse_ip(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
store i8* %0, i8** %3
%4 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %34, label %6
6: ; preds = %2
%7 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %34, label %12
12: ; preds = %9
%13 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %34, label %15
15: ; preds = %12
%16 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 10)
%17 = icmp ugt i32 %16, 255
br i1 %17, label %34, label %18
18: ; preds = %15
%19 = call i32 @strtoul(i8* nocapture %7, i32* null, i32 10)
%20 = icmp ugt i32 %19, 255
br i1 %20, label %34, label %21
21: ; preds = %18
%22 = call i32 @strtoul(i8* nocapture %10, i32* null, i32 10)
%23 = icmp ugt i32 %22, 255
br i1 %23, label %34, label %24
24: ; preds = %21
%25 = call i32 @strtoul(i8* nocapture %13, i32* null, i32 10)
%26 = icmp ugt i32 %25, 255
br i1 %26, label %34, label %27
27: ; preds = %24
%28 = shl nuw i32 %16, 24
%29 = shl nuw nsw i32 %19, 16
%30 = or i32 %29, %28
%31 = shl nuw nsw i32 %22, 8
%32 = or i32 %30, %31
%33 = or i32 %32, %25
store i32 %33, i32* %1
br label %34
34: ; preds = %27, %15, %18, %21, %24, %12, %9, %6, %2
%35 = phi i32 [ 0, %2 ], [ 0, %6 ], [ 0, %9 ], [ 0, %12 ], [ 1, %27 ], [ 0, %15 ], [ 0, %18 ], [ 0, %21 ], [ 0, %24 ]
ret i32 %35
}