#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 uint8_t;

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *, int *);
int parse_ip_address(const char *string, uint8_t address[4]) {
  int parsed[4] = {0};
  int matched = sscanf(string, "%d.%d.%d.%d", &parsed[0], &parsed[1],
                       &parsed[2], &parsed[3]);
  int i;
  for (i = 0; i < 4; i++) {
    if (parsed[i] < 0 || parsed[i] > 255) {
      return -i - 1;
    }
    address[i] = parsed[i];
  }
  return matched == 4;
}


x86 assembly (clang, -O0):
<parse_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    0xe99(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    11d2 <parse_ip_address+0xb2>
movslq -0x38(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jl     11a1 <parse_ip_address+0x81>
movslq -0x38(%rbp),%rax
cmpl   $0xff,-0x30(%rbp,%rax,4)
jle    11b1 <parse_ip_address+0x91>
xor    %eax,%eax
sub    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e1 <parse_ip_address+0xc1>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1176 <parse_ip_address+0x56>
cmpl   $0x4,-0x34(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip_address>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xecb(%rip),%rsi
mov    %rsp,%rdx
call   1030 <sscanf@plt>
mov    (%rsp),%edx
mov    $0xffffffff,%ecx
cmp    $0xff,%edx
ja     1193 <parse_ip_address+0x83>
mov    %edx,(%rbx)
mov    0x4(%rsp),%edx
mov    $0xfffffffe,%ecx
cmp    $0xff,%edx
ja     1193 <parse_ip_address+0x83>
mov    %edx,0x4(%rbx)
mov    0x8(%rsp),%edx
mov    $0xfffffffd,%ecx
cmp    $0xff,%edx
ja     1193 <parse_ip_address+0x83>
mov    %edx,0x8(%rbx)
mov    0xc(%rsp),%edx
mov    $0xfffffffc,%ecx
cmp    $0xff,%edx
ja     1193 <parse_ip_address+0x83>
mov    %edx,0xc(%rbx)
xor    %ecx,%ecx
cmp    $0x4,%eax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @parse_ip_address(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = bitcast [4 x i32]* %6 to i8*
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
%15 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %11, i32* %12, i32* %13, i32* %14)
store i32 %15, i32* %7
store i32 0, i32* %8
br label %16
16: ; preds = %44, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %47
19: ; preds = %16
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = icmp slt i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp sgt i32 %29, 255
br i1 %30, label %31, label %35
31: ; preds = %25, %19
%32 = load i32, i32* %8
%33 = sub nsw i32 0, %32
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %3
br label %51
35: ; preds = %25
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = load i32*, i32** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %35
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %16
47: ; preds = %16
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 4
%50 = zext i1 %49 to i32
store i32 %50, i32* %3
br label %51
51: ; preds = %47, %31
%52 = load i32, i32* %3
ret i32 %52
}

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