#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*/ err_handler(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
int add_argv(char **dest, const char *content) {
  size_t i;
  i = 0;
  while (content[i++] != '\0')
    ;
  if ((*dest = (char *)malloc(i)) == NULL) {
    err_handler("Cannot allocate memory");
    return 0;
  }
  strcpy(*dest, content);
  return 1;
}


x86 assembly (clang, -O0):
<add_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     116d <add_argv+0x3d>
jmp    1148 <add_argv+0x18>
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    119f <add_argv+0x6f>
lea    0xe72(%rip),%rdi
call   1030 <err_handler@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <add_argv+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_argv>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
nopl   0x0(%rax)
cmpb   $0x0,(%rbx,%rdi,1)
lea    0x1(%rdi),%rdi
jne    1140 <add_argv+0x10>
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1169 <add_argv+0x39>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%eax
jmp    1177 <add_argv+0x47>
lea    0xe90(%rip),%rdi
call   1030 <err_handler@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Cannot allocate memory\00"
define i32 @add_argv(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 0, i64* %6
br label %7
7: ; preds = %15, %2
%8 = load i8*, i8** %5
%9 = load i64, i64* %6
%10 = add i64 %9, 1
store i64 %10, i64* %6
%11 = getelementptr inbounds i8, i8* %8, i64 %9
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %7
br label %7
16: ; preds = %7
%17 = load i64, i64* %6
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = load i8**, i8*** %4
store i8* %19, i8** %20
%21 = icmp eq i8* %19, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @err_handler(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %29
24: ; preds = %16
%25 = load i8**, i8*** %4
%26 = load i8*, i8** %25
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
store i32 1, i32* %3
br label %29
29: ; preds = %24, %22
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [23 x i8] c"Cannot allocate memory\00"
define i32 @add_argv(i8** nocapture writeonly %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %5, %3 ]
%5 = add i64 %4, 1
%6 = getelementptr inbounds i8, i8* %1, i64 %4
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i64 @malloc(i64 %5)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %0
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @err_handler(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %9
%16 = tail call i32 @strcpy(i8* %11, i8* %1)
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ 0, %13 ], [ 1, %15 ]
ret i32 %18
}