#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 */
struct in_addr {
  int dummy;
};

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *, int *);
int vc_inet_pton(int family, const char *ipstr, struct in_addr *daddress) {
  int b1, b2, b3, b4;
  char *p = (char *)daddress;
  if (sscanf(ipstr, "%u.%u.%u.%u", &b1, &b2, &b3, &b4) != 4)
    return 0;
  p[0] = b4;
  p[1] = b3;
  p[2] = b2;
  p[3] = b1;
  return 1;
}


x86 assembly (clang, -O0):
<vc_inet_pton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeca(%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
je     1160 <vc_inet_pton+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1196 <vc_inet_pton+0x86>
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x3(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vc_inet_pton>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%rdi
lea    0xede(%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    1161 <vc_inet_pton+0x51>
mov    (%rsp),%al
mov    %al,(%rbx)
mov    0x4(%rsp),%al
mov    %al,0x1(%rbx)
mov    0x8(%rsp),%al
mov    %al,0x2(%rbx)
mov    0xc(%rsp),%al
mov    %al,0x3(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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