#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int sscanf(char const *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int inet_aton(const char *str, struct in_addr *addr) {
  union {
    uint8_t b[4];
    uint32_t l;
  } a;
  if (sscanf(str, "%hhu.%hhu.%hhu.%hhu", &a.b[0], &a.b[1], &a.b[2], &a.b[3]) ==
      4) {
    addr->s_addr = a.l;
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<inet_aton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rdx
lea    -0x28(%rbp),%rcx
add    $0x4,%rcx
lea    -0x28(%rbp),%r8
add    $0x8,%r8
lea    -0x28(%rbp),%r9
add    $0xc,%r9
lea    0xeb9(%rip),%rsi
call   1030 <sscanf@plt>
cmp    $0x4,%eax
jne    116a <inet_aton+0x5a>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1171 <inet_aton+0x61>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_aton>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xed2(%rip),%rsi
mov    %rsp,%rdx
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jne    1149 <inet_aton+0x39>
mov    (%rsp),%eax
mov    %eax,(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%union.anon = type { [4 x i32] }
@.str = [20 x i8] c"%hhu.%hhu.%hhu.%hhu\00"
define i32 @inet_aton(i8* nocapture %0, %struct.in_addr* nocapture writeonly %1) {
%3 = alloca %union.anon
%4 = bitcast %union.anon* %3 to i8*
%5 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 0
%6 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 1
%7 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 2
%8 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 3
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i32 %12, i32* %13
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ 1, %11 ], [ 0, %2 ]
ret i32 %15
}