#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 */
unsigned long atol(char *);
char *strtok(char *, char *);
int parse(char *string, char *dest) {
  int i = 0;
  unsigned long num;
  char *p = string, *n;
  strtok(p, ".");
  while (p && i < 4) {
    if ((num = atol(p)) > 255)
      return 1;
    dest[i++] = num;
    p = strtok(0, ".");
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <strtok@plt>
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x39(%rbp)
je     1169 <parse+0x49>
cmpl   $0x4,-0x1c(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1179 <parse+0x59>
jmp    11d2 <parse+0xb2>
mov    -0x30(%rbp),%rdi
call   1030 <atol@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xff,%rax
jbe    119e <parse+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <parse+0xb9>
mov    -0x28(%rbp),%rax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3c(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    114f <parse+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xeca(%rip),%rsi
call   1040 <strtok@plt>
test   %r13,%r13
je     1188 <parse+0x68>
xor    %ebx,%ebx
lea    0xeb7(%rip),%r14
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <atol@plt>
cmp    $0xff,%rax
ja     118d <parse+0x6d>
mov    %al,(%r15,%rbx,1)
xor    %r12d,%r12d
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1193 <parse+0x73>
mov    %rax,%r13
lea    0x1(%rbx),%rax
cmp    $0x3,%rbx
mov    %rax,%rbx
jb     1150 <parse+0x30>
jmp    1193 <parse+0x73>
xor    %r12d,%r12d
jmp    1193 <parse+0x73>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @parse(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %0, null
br i1 %4, label %18, label %5
5: ; preds = %2, %10
%6 = phi i64 [ %12, %10 ], [ 0, %2 ]
%7 = phi i8* [ %14, %10 ], [ %0, %2 ]
%8 = tail call i64 @atol(i8* %7)
%9 = icmp ugt i64 %8, 255
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = trunc i64 %8 to i8
%12 = add nuw nsw i64 %6, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %11, i8* %13
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i8* %14, null
%16 = icmp ult i64 %6, 3
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %5, label %18
18: ; preds = %5, %10, %2
%19 = phi i32 [ 0, %2 ], [ 0, %10 ], [ 1, %5 ]
ret i32 %19
}