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

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *, int *, char *);
ssize_t parse_ipv4addr(const char *buffer,
                       __attribute__((unused)) const char **error) {
  char c;
  int num, parts[4];
  num = sscanf(buffer, "%d.%d.%d.%d%c", &parts[0], &parts[1], &parts[2],
               &parts[3], &c);
  if (num != 4) {
    return 0;
  }
  for (num = 0; num < 4; num++) {
    if (parts[num] < 0)
      return 0;
    if (parts[num] > 255)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_ipv4addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
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    0xeb9(%rip),%rsi
lea    -0x19(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
je     116d <parse_ipv4addr+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <parse_ipv4addr+0xc1>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11ca <parse_ipv4addr+0xba>
movslq -0x20(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jge    1199 <parse_ipv4addr+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <parse_ipv4addr+0xc1>
movslq -0x20(%rbp),%rax
cmpl   $0xff,-0x30(%rbp,%rax,4)
jle    11b7 <parse_ipv4addr+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <parse_ipv4addr+0xc1>
jmp    11bc <parse_ipv4addr+0xac>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <parse_ipv4addr+0x64>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ipv4addr>:
sub    $0x28,%rsp
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0xf(%rsp),%rax
mov    %rax,(%rsp)
lea    0xecd(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1030 <sscanf@plt>
cmp    $0x4,%eax
sete   %al
cmpl   $0x100,0x10(%rsp)
setb   %cl
and    %al,%cl
cmpl   $0x100,0x14(%rsp)
setb   %al
cmpl   $0x100,0x18(%rsp)
setb   %dl
and    %al,%dl
and    %cl,%dl
cmpl   $0x100,0x1c(%rsp)
setb   %al
and    %dl,%al
movzbl %al,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"%d.%d.%d.%d%c\00"
define i32 @parse_ipv4addr(i8* nocapture %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca [4 x i32]
%5 = bitcast [4 x i32]* %4 to i8*
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%10 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i8* %3)
%11 = icmp eq i32 %10, 4
%12 = load i32, i32* %6
%13 = icmp ult i32 %12, 256
%14 = select i1 %11, i1 %13, i1 false
%15 = load i32, i32* %7
%16 = icmp ult i32 %15, 256
%17 = select i1 %14, i1 %16, i1 false
%18 = load i32, i32* %8
%19 = icmp ult i32 %18, 256
%20 = select i1 %17, i1 %19, i1 false
%21 = load i32, i32* %9
%22 = icmp ult i32 %21, 256
%23 = select i1 %20, i1 %22, i1 false
%24 = zext i1 %23 to i32
ret i32 %24
}