#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 long *, unsigned long *, char *);
unsigned long asn32_to_long(const char *s) {
  unsigned long a, b;
  char junk;
  if (!s)
    return 0;
  if (sscanf(s, "%lu.%lu%c", &a, &b, &junk) != 2)
    return 0;
  if (a > 65535 || b > 65535)
    return 0;
  return (a << 16) + b;
}


x86 assembly (clang, -O0):
<asn32_to_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <asn32_to_long+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119f <asn32_to_long+0x8f>
mov    -0x10(%rbp),%rdi
lea    0xec1(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x21(%rbp),%r8
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     1166 <asn32_to_long+0x56>
movq   $0x0,-0x8(%rbp)
jmp    119f <asn32_to_long+0x8f>
cmpq   $0xffff,-0x18(%rbp)
ja     1182 <asn32_to_long+0x72>
cmpq   $0xffff,-0x20(%rbp)
jbe    118f <asn32_to_long+0x7f>
movq   $0x0,-0x8(%rbp)
jmp    119f <asn32_to_long+0x8f>
mov    -0x18(%rbp),%rax
shl    $0x10,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn32_to_long>:
sub    $0x18,%rsp
test   %rdi,%rdi
je     1166 <asn32_to_long+0x56>
lea    0xee0(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x7(%rsp),%r8
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    1166 <asn32_to_long+0x56>
mov    0x10(%rsp),%rcx
xor    %eax,%eax
cmp    $0xffff,%rcx
ja     1161 <asn32_to_long+0x51>
mov    0x8(%rsp),%rdx
cmp    $0xffff,%rdx
ja     1161 <asn32_to_long+0x51>
shl    $0x10,%rcx
add    %rdx,%rcx
mov    %rcx,%rax
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%lu.%lu%c\00"
define i64 @asn32_to_long(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i64 0, i64* %2
br label %27
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %4, i64* %5, i8* %6)
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %10
store i64 0, i64* %2
br label %27
15: ; preds = %10
%16 = load i64, i64* %4
%17 = icmp ugt i64 %16, 65535
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i64, i64* %5
%20 = icmp ugt i64 %19, 65535
br i1 %20, label %21, label %22
21: ; preds = %18, %15
store i64 0, i64* %2
br label %27
22: ; preds = %18
%23 = load i64, i64* %4
%24 = shl i64 %23, 16
%25 = load i64, i64* %5
%26 = add i64 %24, %25
store i64 %26, i64* %2
br label %27
27: ; preds = %22, %21, %14, %9
%28 = load i64, i64* %2
ret i64 %28
}

LLVM IR (-O2):
@.str = [10 x i8] c"%lu.%lu%c\00"
define i64 @asn32_to_long(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = icmp eq i8* %0, null
br i1 %7, label %20, label %8
8: ; preds = %1
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3, i8* %4)
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i64, i64* %2
%13 = icmp ugt i64 %12, 65535
%14 = load i64, i64* %3
%15 = icmp ugt i64 %14, 65535
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = shl nuw nsw i64 %12, 16
%19 = add nuw nsw i64 %18, %14
br label %20
20: ; preds = %11, %8, %1, %17
%21 = phi i64 [ %19, %17 ], [ 0, %1 ], [ 0, %8 ], [ 0, %11 ]
ret i64 %21
}