#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 /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
char *strchr(char *, char);
int string2addr(char *ipstring, unsigned char *addr) {
  int i;
  char *pptr2, *pptr;
  unsigned int tempaddr[4];
  pptr2 = ipstring;
  for (i = 0; i < 4; i++) {
    if ((pptr = strchr(pptr2, '.')))
      *pptr = '\0';
    sscanf(pptr2, "%u", &tempaddr[i]);
    addr[i] = tempaddr[i];
    pptr2 = pptr + 1;
  }
  return (1);
}


x86 assembly (clang, -O0):
<string2addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11ba <string2addr+0x9a>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     116c <string2addr+0x4c>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
lea    -0x40(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe7a(%rip),%rsi
call   1040 <sscanf@plt>
movslq -0x14(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <string2addr+0x1f>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string2addr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1144 <string2addr+0x24>
movb   $0x0,(%rbx)
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rdi
call   1040 <sscanf@plt>
mov    (%rsp),%al
mov    %al,(%r14)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
je     1179 <string2addr+0x59>
movb   $0x0,(%r15)
lea    0x4(%rsp),%rdx
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    0x4(%rsp),%al
mov    %al,0x1(%r14)
add    $0x1,%r15
mov    %r15,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b1 <string2addr+0x91>
movb   $0x0,(%rbx)
lea    0x8(%rsp),%rdx
lea    0xe43(%rip),%rsi
mov    %r15,%rdi
call   1040 <sscanf@plt>
mov    0x8(%rsp),%al
mov    %al,0x2(%r14)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e6 <string2addr+0xc6>
movb   $0x0,(%rax)
lea    0xc(%rsp),%rdx
lea    0xe0e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    0xc(%rsp),%al
mov    %al,0x3(%r14)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @string2addr(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %2
store i8 0, i8* %5
br label %8
8: ; preds = %7, %2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%10 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = load i32, i32* %9
%12 = trunc i32 %11 to i8
store i8 %12, i8* %1
%13 = getelementptr inbounds i8, i8* %5, i64 1
%14 = call i8* @strchr(i8* dereferenceable(1) %13, i8 signext 46)
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %8
store i8 0, i8* %14
br label %17
17: ; preds = %16, %8
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%19 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %18
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %21, i8* %22
%23 = getelementptr inbounds i8, i8* %14, i64 1
%24 = call i8* @strchr(i8* dereferenceable(1) %23, i8 signext 46)
%25 = icmp eq i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %17
store i8 0, i8* %24
br label %27
27: ; preds = %26, %17
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%29 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %28)
%30 = load i32, i32* %28
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %31, i8* %32
%33 = getelementptr inbounds i8, i8* %24, i64 1
%34 = call i8* @strchr(i8* dereferenceable(1) %33, i8 signext 46)
%35 = icmp eq i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %27
store i8 0, i8* %34
br label %37
37: ; preds = %36, %27
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%39 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %38)
%40 = load i32, i32* %38
%41 = trunc i32 %40 to i8
%42 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %41, i8* %42
ret i32 1
}