#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 **calloc(int, int);
int strlen(char *);
char *strsep(char **, char *);
void parse_ifaces(char *str, char ***ifaces, int *num_ifaces) {
  int max_ifaces = strlen(str) / 2 + 1;
  *ifaces = calloc(max_ifaces, sizeof(char *));
  *num_ifaces = 0;
  while (((*ifaces)[*num_ifaces] = strsep(&str, ","))) {
    if ((*ifaces)[*num_ifaces] != NULL && (*ifaces)[*num_ifaces][0] != '\0') {
      (*num_ifaces)++;
    }
  }
}


x86 assembly (clang, -O0):
<parse_ifaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strsep@plt>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x18(%rbp),%rdx
movslq (%rdx),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     11ef <parse_ifaces+0xbf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ea <parse_ifaces+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ea <parse_ifaces+0xba>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    117c <parse_ifaces+0x4c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ifaces>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,(%rsp)
call   1030 <strlen@plt>
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx)
movl   $0x0,(%r14)
lea    0xe92(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
mov    (%rbx),%rsi
mov    (%r14),%ecx
movslq %ecx,%rdx
mov    %rax,(%rsi,%rdx,8)
test   %rax,%rax
je     11d6 <parse_ifaces+0xa6>
lea    0xe71(%rip),%r15
mov    %rsp,%r12
jmp    11bd <parse_ifaces+0x8d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strsep@plt>
mov    (%rbx),%rsi
mov    (%r14),%ecx
movslq %ecx,%rdx
mov    %rax,(%rsi,%rdx,8)
test   %rax,%rax
je     11d6 <parse_ifaces+0xa6>
mov    (%rbx),%rax
mov    (%rax,%rdx,8),%rax
test   %rax,%rax
je     11a0 <parse_ifaces+0x70>
cmpb   $0x0,(%rax)
je     11a0 <parse_ifaces+0x70>
add    $0x1,%ecx
mov    %ecx,(%r14)
jmp    11a0 <parse_ifaces+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define void @parse_ifaces(i8* %0, i8*** nocapture %1, i32* nocapture %2) {
%4 = alloca i8*
store i8* %0, i8** %4
%5 = tail call i32 @strlen(i8* %0)
%6 = sdiv i32 %5, 2
%7 = add nsw i32 %6, 1
%8 = tail call i8** @calloc(i32 %7, i32 8)
store i8** %8, i8*** %1
store i32 0, i32* %2
%9 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = load i8**, i8*** %1
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
store i8* %9, i8** %13
%14 = icmp eq i8* %9, null
br i1 %14, label %34, label %15
15: ; preds = %3, %27
%16 = phi i64 [ %31, %27 ], [ %12, %3 ]
%17 = phi i32 [ %30, %27 ], [ %11, %3 ]
%18 = load i8**, i8*** %1
%19 = getelementptr inbounds i8*, i8** %18, i64 %16
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = load i8, i8* %20
%24 = icmp eq i8 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = add nsw i32 %17, 1
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %22, %15
%28 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = load i8**, i8*** %1
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
store i8* %28, i8** %32
%33 = icmp eq i8* %28, null
br i1 %33, label %34, label %15
34: ; preds = %27, %3
ret void
}