#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*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
void parse_address(char *addr, int *addr0, int *addr1, int *addr2, int *addr3) {
  int strlength;
  char *addrcpy;
  char *token;
  strlength = 0;
  addrcpy = (char *)malloc(sizeof(char) * strlen(addr) + 1);
  strcpy(addrcpy, addr);
  token = strtok(addrcpy, ".");
  if (token != NULL) {
    *addr0 = atoi(token);
    strlength++;
    token = strtok(NULL, ".");
    if (token != NULL) {
      strlength++;
      *addr1 = atoi(token);
      token = strtok(NULL, ".");
      if (token != NULL) {
        strlength++;
        *addr2 = atoi(token);
        token = strtok(NULL, ".");
        if (token != NULL) {
          strlength++;
          *addr3 = atoi(token);
        }
      }
    }
  }
  free(addrcpy);
  if (strlength != 4) {
    fprintf(stderr, "Bad address %s\n", addr);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<parse_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12c1 <parse_address+0x141>
mov    -0x40(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdee(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12bc <parse_address+0x13c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb5(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12b7 <parse_address+0x137>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7c(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12b2 <parse_address+0x132>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b7 <parse_address+0x137>
jmp    12bc <parse_address+0x13c>
jmp    12c1 <parse_address+0x141>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x4,-0x2c(%rbp)
je     12fb <parse_address+0x17b>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd1a(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1246 <parse_address+0xc6>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,0x0(%rbp)
lea    0xe25(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1246 <parse_address+0xc6>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,0x0(%r13)
lea    0xe06(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1246 <parse_address+0xc6>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r12)
lea    0xde7(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1246 <parse_address+0xc6>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Bad address %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @parse_address(i8* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 0, i32* %11
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = add i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %12
%22 = load i8*, i8** %12
%23 = load i8*, i8** %6
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %12
%26 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %13
%27 = load i8*, i8** %13
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %65
29: ; preds = %5
%30 = load i8*, i8** %13
%31 = call i32 @atoi(i8* %30)
%32 = load i32*, i32** %7
store i32 %31, i32* %32
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %13
%36 = load i8*, i8** %13
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %64
38: ; preds = %29
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
%41 = load i8*, i8** %13
%42 = call i32 @atoi(i8* %41)
%43 = load i32*, i32** %8
store i32 %42, i32* %43
%44 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %44, i8** %13
%45 = load i8*, i8** %13
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %63
47: ; preds = %38
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
%50 = load i8*, i8** %13
%51 = call i32 @atoi(i8* %50)
%52 = load i32*, i32** %9
store i32 %51, i32* %52
%53 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %53, i8** %13
%54 = load i8*, i8** %13
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %62
56: ; preds = %47
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
%59 = load i8*, i8** %13
%60 = call i32 @atoi(i8* %59)
%61 = load i32*, i32** %10
store i32 %60, i32* %61
br label %62
62: ; preds = %56, %47
br label %63
63: ; preds = %62, %38
br label %64
64: ; preds = %63, %29
br label %65
65: ; preds = %64, %5
%66 = load i8*, i8** %12
%67 = call i32 @free(i8* %66)
%68 = load i32, i32* %11
%69 = icmp ne i32 %68, 4
br i1 %69, label %70, label %76
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %6
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %65
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Bad address %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @parse_address(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = tail call i32 @strlen(i8* %0)
%7 = add i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
%11 = tail call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %28, label %13
13: ; preds = %5
%14 = tail call i32 @atoi(i8* %11)
store i32 %14, i32* %1
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %13
%18 = tail call i32 @atoi(i8* %15)
store i32 %18, i32* %2
%19 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = tail call i32 @atoi(i8* %19)
store i32 %22, i32* %3
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = tail call i32 @atoi(i8* %23)
store i32 %26, i32* %4
%27 = tail call i32 @free(i8* %9)
ret void
28: ; preds = %21, %13, %5, %17
%29 = tail call i32 @free(i8* %9)
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
}