#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sscanf(char const *, char *, int *, int *, int *, int *);
uint32_t inet_addr(const char *ip_addr) {
  int a, b, c, d;
  char addr[4];
  sscanf(ip_addr, "%d.%d.%d.%d", &a, &b, &c, &d);
  addr[0] = a;
  addr[1] = b;
  addr[2] = c;
  addr[3] = d;
  return *(uint32_t *)addr;
}


x86 assembly (clang, -O0):
<inet_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed9(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1030 <sscanf@plt>
mov    -0xc(%rbp),%eax
mov    %al,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,-0x1b(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x19(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_addr>:
sub    $0x18,%rsp
lea    0xee5(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1030 <sscanf@plt>
movzbl 0x14(%rsp),%ecx
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%esi
shl    $0x18,%esi
movzbl %dl,%edx
shl    $0x10,%edx
or     %esi,%edx
shl    $0x8,%eax
movzwl %ax,%eax
or     %edx,%eax
or     %ecx,%eax
add    $0x18,%rsp
ret

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

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