#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 unsigned int uint32_t;

/* Variables and functions */
int sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *);
int atoip(const char *str, uint32_t *ip) {
  unsigned a, b, c, d;
  if (sscanf(str, "%u.%u.%u.%u", &a, &b, &c, &d) != 4 || a > 255 || b > 255 ||
      c > 255 || d > 255)
    return 1;
  *ip = a * 0x1000000 + b * 0x10000 + c * 0x100 + d;
  return 0;
}


x86 assembly (clang, -O0):
<atoip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1030 <sscanf@plt>
cmp    $0x4,%eax
jne    117d <atoip+0x6d>
cmpl   $0xff,-0x1c(%rbp)
ja     117d <atoip+0x6d>
cmpl   $0xff,-0x20(%rbp)
ja     117d <atoip+0x6d>
cmpl   $0xff,-0x24(%rbp)
ja     117d <atoip+0x6d>
cmpl   $0xff,-0x28(%rbp)
jbe    1189 <atoip+0x79>
movl   $0x1,-0x4(%rbp)
jmp    11af <atoip+0x9f>
mov    -0x1c(%rbp),%ecx
shl    $0x18,%ecx
mov    -0x20(%rbp),%eax
shl    $0x10,%eax
add    %eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x8,%eax
add    %eax,%ecx
add    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoip>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xee1(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x4,%ecx
jne    1184 <atoip+0x74>
mov    0xc(%rsp),%ecx
cmp    $0xff,%ecx
ja     1184 <atoip+0x74>
mov    0x8(%rsp),%edx
cmp    $0xff,%edx
ja     1184 <atoip+0x74>
mov    0x4(%rsp),%esi
cmp    $0xff,%esi
ja     1184 <atoip+0x74>
mov    (%rsp),%edi
cmp    $0xff,%edi
ja     1184 <atoip+0x74>
shl    $0x18,%ecx
shl    $0x10,%edx
add    %ecx,%edx
shl    $0x8,%esi
add    %edx,%esi
add    %edi,%esi
mov    %esi,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @atoip(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i8*, i8** %4
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9)
%12 = icmp ne i32 %11, 4
br i1 %12, label %25, label %13
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp ugt i32 %14, 255
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp ugt i32 %17, 255
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i32, i32* %8
%21 = icmp ugt i32 %20, 255
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %9
%24 = icmp ugt i32 %23, 255
br i1 %24, label %25, label %26
25: ; preds = %22, %19, %16, %13, %2
store i32 1, i32* %3
br label %38
26: ; preds = %22
%27 = load i32, i32* %6
%28 = mul i32 %27, 16777216
%29 = load i32, i32* %7
%30 = mul i32 %29, 65536
%31 = add i32 %28, %30
%32 = load i32, i32* %8
%33 = mul i32 %32, 256
%34 = add i32 %31, %33
%35 = load i32, i32* %9
%36 = add i32 %34, %35
%37 = load i32*, i32** %5
store i32 %36, i32* %37
store i32 0, i32* %3
br label %38
38: ; preds = %26, %25
%39 = load i32, i32* %3
ret i32 %39
}

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