#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 */
bool collect_arg(char **argv, int *arg_ptr, const char **collected_arg) {
  if ((argv == NULL) || (argv[*arg_ptr] == NULL)) {
    *collected_arg = NULL;
    return false;
  }
  *collected_arg = argv[*arg_ptr];
  (*arg_ptr)++;
  return true;
}


x86 assembly (clang, -O0):
<collect_arg>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1131 <collect_arg+0x31>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1148 <collect_arg+0x48>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1170 <collect_arg+0x70>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<collect_arg>:
test   %rdi,%rdi
je     111f <collect_arg+0x1f>
movslq (%rsi),%rax
mov    (%rdi,%rax,8),%rcx
test   %rcx,%rcx
je     111f <collect_arg+0x1f>
mov    %rcx,(%rdx)
add    $0x1,%eax
mov    %eax,(%rsi)
mov    $0x1,%eax
ret
movq   $0x0,(%rdx)
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i32 @collect_arg(i8** %0, i32* nocapture %1, i8** nocapture writeonly %2) {
%4 = icmp eq i8** %0, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = load i32, i32* %1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8*, i8** %0, i64 %7
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %5, %3
store i8* null, i8** %2
br label %14
12: ; preds = %5
store i8* %9, i8** %2
%13 = add nsw i32 %6, 1
store i32 %13, i32* %1
br label %14
14: ; preds = %12, %11
%15 = phi i32 [ 0, %11 ], [ 1, %12 ]
ret i32 %15
}