#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 */
int sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *);
int string_to_ip_address(const char *str, unsigned char *bytes) {
  unsigned a, b, c, d;
  int fields;
  fields = sscanf(str, "%u.%u.%u.%u", &a, &b, &c, &d);
  if (fields != 4)
    return 0;
  if (a > 255 || b > 255 || c > 255 || d > 255)
    return 0;
  bytes[0] = a;
  bytes[1] = b;
  bytes[2] = c;
  bytes[3] = d;
  return 1;
}


x86 assembly (clang, -O0):
<string_to_ip_address>:
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>
mov    %eax,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
je     1159 <string_to_ip_address+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11cf <string_to_ip_address+0xbf>
cmpl   $0xff,-0x1c(%rbp)
ja     118d <string_to_ip_address+0x7d>
cmpl   $0xff,-0x20(%rbp)
ja     118d <string_to_ip_address+0x7d>
cmpl   $0xff,-0x24(%rbp)
ja     118d <string_to_ip_address+0x7d>
cmpl   $0xff,-0x28(%rbp)
jbe    1199 <string_to_ip_address+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11cf <string_to_ip_address+0xbf>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_ip_address>:
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
xor    %eax,%eax
cmp    $0x4,%ecx
jne    1180 <string_to_ip_address+0x70>
mov    0xc(%rsp),%ecx
cmp    $0xff,%ecx
ja     1180 <string_to_ip_address+0x70>
mov    0x8(%rsp),%edx
cmp    $0xff,%edx
ja     1180 <string_to_ip_address+0x70>
mov    0x4(%rsp),%esi
cmp    $0xff,%esi
ja     1180 <string_to_ip_address+0x70>
mov    (%rsp),%edi
cmp    $0xff,%edi
ja     1180 <string_to_ip_address+0x70>
mov    %cl,(%rbx)
mov    %dl,0x1(%rbx)
mov    %sil,0x2(%rbx)
mov    %dil,0x3(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @string_to_ip_address(i8* nocapture %0, i8* 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 eq i32 %11, 4
br i1 %12, label %13, label %33
13: ; preds = %2
%14 = load i32, i32* %3
%15 = icmp ugt i32 %14, 255
%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 %33, label %25
25: ; preds = %13
%26 = trunc i32 %14 to i8
store i8 %26, i8* %1
%27 = trunc i32 %16 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %27, i8* %28
%29 = trunc i32 %19 to i8
%30 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %29, i8* %30
%31 = trunc i32 %22 to i8
%32 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %31, i8* %32
br label %33
33: ; preds = %13, %2, %25
%34 = phi i32 [ 1, %25 ], [ 0, %2 ], [ 0, %13 ]
ret i32 %34
}