#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 atoi(char *);
int ipv6_addr_split(char *addr_str, char seperator, int _default) {
  char *sep = addr_str;
  while (*++sep) {
    if (*sep == seperator) {
      *sep++ = '\0';
      if (*sep) {
        _default = atoi(sep);
      }
      break;
    }
  }
  return _default;
}


x86 assembly (clang, -O0):
<ipv6_addr_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,0x1(%rax)
je     118e <ipv6_addr_split+0x7e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1189 <ipv6_addr_split+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1184 <ipv6_addr_split+0x74>
mov    -0x18(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0x10(%rbp)
jmp    118e <ipv6_addr_split+0x7e>
jmp    112d <ipv6_addr_split+0x1d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv6_addr_split>:
add    $0x1,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rdi),%eax
test   %al,%al
je     113e <ipv6_addr_split+0x2e>
add    $0x1,%rdi
cmp    %sil,%al
jne    1120 <ipv6_addr_split+0x10>
movb   $0x0,-0x1(%rdi)
cmpb   $0x0,(%rdi)
je     113e <ipv6_addr_split+0x2e>
jmp    1030 <atoi@plt>
mov    %edx,%eax
ret

LLVM IR (-O0):
define i32 @ipv6_addr_split(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
br label %9
9: ; preds = %31, %3
%10 = load i8*, i8** %7
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %7
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %31
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
store i8 0, i8* %22
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
br label %30
30: ; preds = %27, %21
br label %32
31: ; preds = %14
br label %9
32: ; preds = %30, %9
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
define i32 @ipv6_addr_split(i8* nocapture %0, i8 signext %1, i32 %2) {
br label %4
4: ; preds = %9, %3
%5 = phi i8* [ %0, %3 ], [ %6, %9 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = icmp eq i8 %7, %1
br i1 %10, label %11, label %4
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %5, i64 2
store i8 0, i8* %6
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @atoi(i8* %12)
br label %17
17: ; preds = %4, %11, %15
%18 = phi i32 [ %16, %15 ], [ %2, %11 ], [ %2, %4 ]
ret i32 %18
}