#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 /*<<< orphan*/ s_addr;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *strchr(char *, char);
int string_to_number(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
struct in_addr *dotted_to_addr(const char *dotted) {
  static struct in_addr addr;
  unsigned char *addrp;
  char *p, *q;
  int onebyte, i;
  char buf[20];
  strncpy(buf, dotted, sizeof(buf) - 1);
  addrp = (unsigned char *)&(addr.s_addr);
  p = buf;
  for (i = 0; i < 3; i++) {
    if ((q = strchr(p, '.')) == NULL)
      return (struct in_addr *)NULL;
    else {
      *q = '\0';
      if ((onebyte = string_to_number(p, 0, 255)) == -1)
        return (struct in_addr *)NULL;
      else
        addrp[i] = (unsigned char)onebyte;
    }
    p = q + 1;
  }
  if ((onebyte = string_to_number(p, 0, 255)) == -1)
    return (struct in_addr *)NULL;
  else
    addrp[3] = (unsigned char)onebyte;
  return &addr;
}


x86 assembly (clang, -O0):
<dotted_to_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x13,%edx
call   1030 <strncpy@plt>
lea    0x2ee7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    11fa <dotted_to_addr+0xca>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    119b <dotted_to_addr+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    123a <dotted_to_addr+0x10a>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <dotted_to_addr+0x9b>
movq   $0x0,-0x8(%rbp)
jmp    123a <dotted_to_addr+0x10a>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11e0 <dotted_to_addr+0xb0>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1168 <dotted_to_addr+0x38>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    1223 <dotted_to_addr+0xf3>
movq   $0x0,-0x8(%rbp)
jmp    123a <dotted_to_addr+0x10a>
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
lea    0x2e06(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotted_to_addr>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x13,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1229 <dotted_to_addr+0xf9>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rsp,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
cmp    $0xffffffff,%eax
je     122c <dotted_to_addr+0xfc>
mov    %al,0x2eb3(%rip)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1229 <dotted_to_addr+0xf9>
mov    %rax,%r15
movb   $0x0,(%rax)
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
cmp    $0xffffffff,%eax
je     122c <dotted_to_addr+0xfc>
mov    %al,0x2e77(%rip)
add    $0x1,%r15
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1229 <dotted_to_addr+0xf9>
mov    %rax,%rbx
movb   $0x0,(%rax)
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
cmp    $0xffffffff,%eax
je     122c <dotted_to_addr+0xfc>
mov    %al,0x2e3f(%rip)
add    $0x1,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <string_to_number@plt>
cmp    $0xffffffff,%eax
je     122c <dotted_to_addr+0xfc>
mov    %al,0x2e1f(%rip)
lea    0x2e15(%rip),%r14
jmp    122c <dotted_to_addr+0xfc>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@dotted_to_addr.addr = internal global %struct.in_addr zeroinitializer
define %struct.in_addr* @dotted_to_addr(i8* %0) {
%2 = alloca %struct.in_addr*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [20 x i8]
store i8* %0, i8** %3
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 19)
store i8* bitcast (%struct.in_addr* @dotted_to_addr.addr to i8*), i8** %4
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
store i8* %13, i8** %5
store i32 0, i32* %8
br label %14
14: ; preds = %39, %1
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %42
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = call i8* @strchr(i8* %18, i8 signext 46)
store i8* %19, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
store %struct.in_addr* null, %struct.in_addr** %2
br label %53
22: ; preds = %17
%23 = load i8*, i8** %6
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = call i32 @string_to_number(i8* %24, i32 0, i32 255)
store i32 %25, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %22
store %struct.in_addr* null, %struct.in_addr** %2
br label %53
28: ; preds = %22
%29 = load i32, i32* %7
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %28
br label %36
36: ; preds = %35
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %5
br label %39
39: ; preds = %36
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %14
42: ; preds = %14
%43 = load i8*, i8** %5
%44 = call i32 @string_to_number(i8* %43, i32 0, i32 255)
store i32 %44, i32* %7
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %42
store %struct.in_addr* null, %struct.in_addr** %2
br label %53
47: ; preds = %42
%48 = load i32, i32* %7
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 3
store i8 %49, i8* %51
br label %52
52: ; preds = %47
store %struct.in_addr* @dotted_to_addr.addr, %struct.in_addr** %2
br label %53
53: ; preds = %52, %46, %27, %21
%54 = load %struct.in_addr*, %struct.in_addr** %2
ret %struct.in_addr* %54
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@dotted_to_addr.addr = internal global %struct.in_addr zeroinitializer
define %struct.in_addr* @dotted_to_addr(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 19)
%5 = call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %33, label %7
7: ; preds = %1
store i8 0, i8* %5
%8 = call i32 @string_to_number(i8* %3, i32 0, i32 255)
%9 = icmp eq i32 %8, -1
br i1 %9, label %33, label %10
10: ; preds = %7
%11 = trunc i32 %8 to i8
store i8 %11, i8* bitcast (%struct.in_addr* @dotted_to_addr.addr to i8*)
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %33, label %15
15: ; preds = %10
store i8 0, i8* %13
%16 = call i32 @string_to_number(i8* %12, i32 0, i32 255)
%17 = icmp eq i32 %16, -1
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = trunc i32 %16 to i8
store i8 %19, i8* getelementptr inbounds (i8, i8* bitcast (%struct.in_addr* @dotted_to_addr.addr to i8*), i64 1)
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = call i8* @strchr(i8* dereferenceable(1) %20, i8 signext 46)
%22 = icmp eq i8* %21, null
br i1 %22, label %33, label %23
23: ; preds = %18
store i8 0, i8* %21
%24 = call i32 @string_to_number(i8* %20, i32 0, i32 255)
%25 = icmp eq i32 %24, -1
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = trunc i32 %24 to i8
store i8 %27, i8* getelementptr inbounds (i8, i8* bitcast (%struct.in_addr* @dotted_to_addr.addr to i8*), i64 2)
%28 = getelementptr inbounds i8, i8* %21, i64 1
%29 = call i32 @string_to_number(i8* %28, i32 0, i32 255)
%30 = icmp eq i32 %29, -1
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = trunc i32 %29 to i8
store i8 %32, i8* getelementptr inbounds (i8, i8* bitcast (%struct.in_addr* @dotted_to_addr.addr to i8*), i64 3)
br label %33
33: ; preds = %7, %1, %10, %15, %18, %23, %26, %31
%34 = phi %struct.in_addr* [ @dotted_to_addr.addr, %31 ], [ null, %26 ], [ null, %23 ], [ null, %18 ], [ null, %15 ], [ null, %10 ], [ null, %1 ], [ null, %7 ]
ret %struct.in_addr* %34
}