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

/* Variables and functions */
int htonl(int);
int /*<<< orphan*/ sscanf(char const *, char *, int *, int *, int *, int *);
u_int32_t str_to_addr(const char *addr) {
  u_int32_t split[4];
  u_int32_t ip;
  sscanf(addr, "%d.%d.%d.%d", &split[0], &split[1], &split[2], &split[3]);
  ip = (split[0] << 24) | (split[1] << 16) | (split[2] << 8) | (split[3]);
  return htonl(ip);
}


x86 assembly (clang, -O0):
<str_to_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xead(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x20(%rbp),%eax
shl    $0x18,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <htonl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_addr>:
sub    $0x18,%rsp
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xec6(%rip),%rsi
mov    %rsp,%rdx
call   1040 <sscanf@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
shl    $0x18,%eax
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x8(%rsp),%edi
shl    $0x8,%edi
or     %ecx,%edi
or     0xc(%rsp),%edi
call   1030 <htonl@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @str_to_addr(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i32]
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%10 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9)
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%12 = load i32, i32* %11
%13 = shl i32 %12, 24
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = shl i32 %15, 16
%17 = or i32 %13, %16
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%19 = load i32, i32* %18
%20 = shl i32 %19, 8
%21 = or i32 %17, %20
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%23 = load i32, i32* %22
%24 = or i32 %21, %23
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = call i32 @htonl(i32 %25)
ret i32 %26
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @str_to_addr(i8* nocapture %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6, i32* %7)
%9 = load i32, i32* %4
%10 = shl i32 %9, 24
%11 = load i32, i32* %5
%12 = shl i32 %11, 16
%13 = or i32 %12, %10
%14 = load i32, i32* %6
%15 = shl i32 %14, 8
%16 = or i32 %13, %15
%17 = load i32, i32* %7
%18 = or i32 %16, %17
%19 = call i32 @htonl(i32 %18)
ret i32 %19
}