#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 */
char ATOI(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
void inet_addr_(unsigned char *addr, unsigned char *ip) {
  int i;
  char taddr[30];
  char *nexttok;
  char num;
  strcpy(taddr, (char *)addr);
  nexttok = taddr;
  for (i = 0; i < 4; i++) {
    nexttok = strtok(nexttok, ".");
    if (nexttok[0] == '0' && nexttok[1] == 'x')
      num = ATOI(nexttok + 2, 0x10);
    else
      num = ATOI(nexttok, 10);
    ip[i] = num;
    nexttok = ((void *)0);
  }
}


x86 assembly (clang, -O0):
<inet_addr_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11ea <inet_addr_+0xba>
mov    -0x48(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11b5 <inet_addr_+0x85>
mov    -0x48(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11b5 <inet_addr_+0x85>
mov    -0x48(%rbp),%rdi
add    $0x2,%rdi
mov    $0x10,%esi
call   1040 <ATOI@plt>
mov    %al,-0x49(%rbp)
jmp    11c6 <inet_addr_+0x96>
mov    -0x48(%rbp),%rdi
mov    $0xa,%esi
call   1040 <ATOI@plt>
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movq   $0x0,-0x48(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <inet_addr_+0x2c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_addr_>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
cmpb   $0x30,(%rax)
jne    1170 <inet_addr_+0x40>
cmpb   $0x78,0x1(%rax)
jne    1170 <inet_addr_+0x40>
add    $0x2,%rax
mov    %rax,%rdi
mov    $0x10,%esi
jmp    1178 <inet_addr_+0x48>
mov    %rax,%rdi
mov    $0xa,%esi
call   1040 <ATOI@plt>
mov    %al,(%r14)
lea    0xe79(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
cmpb   $0x30,(%rax)
jne    11a7 <inet_addr_+0x77>
cmpb   $0x78,0x1(%rax)
jne    11a7 <inet_addr_+0x77>
add    $0x2,%rax
mov    %rax,%rdi
mov    $0x10,%esi
jmp    11af <inet_addr_+0x7f>
mov    %rax,%rdi
mov    $0xa,%esi
call   1040 <ATOI@plt>
mov    %al,0x1(%r14)
lea    0xe41(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
cmpb   $0x30,(%rax)
jne    11df <inet_addr_+0xaf>
cmpb   $0x78,0x1(%rax)
jne    11df <inet_addr_+0xaf>
add    $0x2,%rax
mov    %rax,%rdi
mov    $0x10,%esi
jmp    11e7 <inet_addr_+0xb7>
mov    %rax,%rdi
mov    $0xa,%esi
call   1040 <ATOI@plt>
mov    %al,0x2(%r14)
lea    0xe09(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
cmpb   $0x30,(%rax)
jne    1217 <inet_addr_+0xe7>
cmpb   $0x78,0x1(%rax)
jne    1217 <inet_addr_+0xe7>
add    $0x2,%rax
mov    %rax,%rdi
mov    $0x10,%esi
jmp    121f <inet_addr_+0xef>
mov    %rax,%rdi
mov    $0xa,%esi
call   1040 <ATOI@plt>
mov    %al,0x3(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @inet_addr_(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = alloca i8*
%8 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %7
store i32 0, i32* %5
br label %13
13: ; preds = %43, %2
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %46
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 48
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 120
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 2
%33 = call signext i8 @ATOI(i8* %32, i32 16)
store i8 %33, i8* %8
br label %37
34: ; preds = %24, %16
%35 = load i8*, i8** %7
%36 = call signext i8 @ATOI(i8* %35, i32 10)
store i8 %36, i8* %8
br label %37
37: ; preds = %34, %30
%38 = load i8, i8* %8
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
store i8* null, i8** %7
br label %43
43: ; preds = %37
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %13
46: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @inet_addr_(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 48
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 120
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %6, i64 2
%15 = call signext i8 @ATOI(i8* %14, i32 16)
br label %18
16: ; preds = %9, %2
%17 = call signext i8 @ATOI(i8* %6, i32 10)
br label %18
18: ; preds = %16, %13
%19 = phi i8 [ %15, %13 ], [ %17, %16 ]
store i8 %19, i8* %1
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 48
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 120
br i1 %26, label %29, label %27
27: ; preds = %23, %18
%28 = call signext i8 @ATOI(i8* %20, i32 10)
br label %32
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %20, i64 2
%31 = call signext i8 @ATOI(i8* %30, i32 16)
br label %32
32: ; preds = %29, %27
%33 = phi i8 [ %31, %29 ], [ %28, %27 ]
%34 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %33, i8* %34
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 48
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = getelementptr inbounds i8, i8* %35, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 120
br i1 %41, label %44, label %42
42: ; preds = %38, %32
%43 = call signext i8 @ATOI(i8* %35, i32 10)
br label %47
44: ; preds = %38
%45 = getelementptr inbounds i8, i8* %35, i64 2
%46 = call signext i8 @ATOI(i8* %45, i32 16)
br label %47
47: ; preds = %44, %42
%48 = phi i8 [ %46, %44 ], [ %43, %42 ]
%49 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %48, i8* %49
%50 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 48
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = getelementptr inbounds i8, i8* %50, i64 1
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 120
br i1 %56, label %59, label %57
57: ; preds = %53, %47
%58 = call signext i8 @ATOI(i8* %50, i32 10)
br label %62
59: ; preds = %53
%60 = getelementptr inbounds i8, i8* %50, i64 2
%61 = call signext i8 @ATOI(i8* %60, i32 16)
br label %62
62: ; preds = %59, %57
%63 = phi i8 [ %61, %59 ], [ %58, %57 ]
%64 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %63, i8* %64
ret void
}