#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 /*<<< orphan*/ usage(int);
char *getstring(char ***avp, int *flagp) {
  char **a = *avp;
  usage((*flagp)++);
  if (*++*a)
    return *a;
  ++a;
  usage(!*a);
  *avp = a;
  return *a;
}


x86 assembly (clang, -O0):
<getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    %edi,%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
call   1030 <usage@plt>
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
cmpb   $0x0,0x1(%rax)
je     1168 <getstring+0x58>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <getstring+0x91>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <usage@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    (%rsi),%edi
lea    0x1(%rdi),%eax
mov    %eax,(%rsi)
call   1030 <usage@plt>
mov    (%rbx),%rcx
lea    0x1(%rcx),%rax
mov    %rax,(%rbx)
cmpb   $0x0,0x1(%rcx)
jne    1152 <getstring+0x42>
lea    0x8(%rbx),%r15
xor    %edi,%edi
cmpq   $0x0,0x8(%rbx)
sete   %dil
call   1030 <usage@plt>
mov    %r15,(%r14)
mov    0x8(%rbx),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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