#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 */
size_t strlen(char const *);
void argz_extract(const char *argz, size_t len, char **argv) {
  while (len > 0) {
    size_t part_len = strlen(argz);
    *argv++ = (char *)argz;
    argz += part_len + 1;
    len -= part_len + 1;
  }
  *argv = 0;
}


x86 assembly (clang, -O0):
<argz_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    117a <argz_extract+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <argz_extract+0x14>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argz_extract>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
test   %rsi,%rsi
je     114f <argz_extract+0x3f>
mov    %rsi,%r14
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,(%r15)
add    $0x8,%r15
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%rax
sub    %rax,%r14
jne    1130 <argz_extract+0x20>
movq   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @argz_extract(i8* %0, i64 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8** %2, i8*** %6
br label %8
8: ; preds = %11, %3
%9 = load i64, i64* %5
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i8*, i8** %4
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %6
store i8* %14, i8** %15
%17 = load i64, i64* %7
%18 = add i64 %17, 1
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 %18
store i8* %20, i8** %4
%21 = load i64, i64* %7
%22 = add i64 %21, 1
%23 = load i64, i64* %5
%24 = sub i64 %23, %22
store i64 %24, i64* %5
br label %8
25: ; preds = %8
%26 = load i8**, i8*** %6
store i8* null, i8** %26
ret void
}

LLVM IR (-O2):
define void @argz_extract(i8* %0, i64 %1, i8** nocapture writeonly %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %15, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %12, %5 ], [ %0, %3 ]
%7 = phi i8** [ %10, %5 ], [ %2, %3 ]
%8 = phi i64 [ %13, %5 ], [ %1, %3 ]
%9 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%10 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* %6, i8** %7
%11 = add i64 %9, 1
%12 = getelementptr inbounds i8, i8* %6, i64 %11
%13 = sub i64 %8, %11
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %3
%16 = phi i8** [ %2, %3 ], [ %10, %5 ]
store i8* null, i8** %16
ret void
}