#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 /*<<< orphan*/ gpm_report(int, char *, int, char *);
char *strchr(char *, char);
char *strdup(char *);
char **build_argv(char *argv0, char *str, int *argcptr, char sep) {
  int argc = 1;
  char **argv;
  char *s;
  if (str)
    for (s = str; sep && (s = strchr(s, sep)); argc++)
      s++;
  argv = calloc(argc + 2, sizeof(char **));
  if (!argv)
    gpm_report(125,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/"
               "heads/master/lib/gpm/src/gpm.c",
               6, "allocation failed!");
  argv[0] = argv0;
  if (!str) {
    *argcptr = argc;
    return argv;
  }
  s = argv[1] = strdup(str);
  argc = 2;
  for (; sep && (s = strchr(s, sep)); argc++) {
    *s = '\0';
    s++;
    argv[argc] = s;
  }
  *argcptr = argc;
  return argv;
}


x86 assembly (clang, -O0):
<build_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movl   $0x1,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cf <build_argv+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11a0 <build_argv+0x60>
mov    -0x38(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11b0 <build_argv+0x70>
jmp    11ca <build_argv+0x8a>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1173 <build_argv+0x33>
jmp    11cf <build_argv+0x8f>
mov    -0x28(%rbp),%edi
add    $0x2,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120b <build_argv+0xcb>
mov    $0x7d,%edi
lea    0xe06(%rip),%rsi
mov    $0x6,%edx
lea    0xe8f(%rip),%rcx
call   1050 <gpm_report@plt>
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    1237 <build_argv+0xf7>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <build_argv+0x192>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,0x8(%rcx)
mov    %rax,-0x38(%rbp)
movl   $0x2,-0x28(%rbp)
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x3a(%rbp)
je     1280 <build_argv+0x140>
mov    -0x38(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    1290 <build_argv+0x150>
jmp    12c1 <build_argv+0x181>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1253 <build_argv+0x113>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rsi,%r13
mov    %rdi,%r12
mov    $0x1,%ebx
test   %rsi,%rsi
mov    %rdx,(%rsp)
je     1196 <build_argv+0x56>
test   %r15b,%r15b
je     1196 <build_argv+0x56>
movsbl %r15b,%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1196 <build_argv+0x56>
mov    $0x1,%ebx
nop
add    $0x1,%rax
add    $0x1,%ebx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1180 <build_argv+0x40>
lea    0x2(%rbx),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c8 <build_argv+0x88>
lea    0xe4e(%rip),%rsi
lea    0xedc(%rip),%rcx
mov    $0x7d,%edi
mov    $0x6,%edx
call   1050 <gpm_report@plt>
mov    %r12,(%r14)
test   %r13,%r13
je     121e <build_argv+0xde>
mov    %r13,%rdi
call   1060 <strdup@plt>
mov    %rax,0x8(%r14)
mov    $0x2,%ebx
test   %r15b,%r15b
je     121e <build_argv+0xde>
movsbl %r15b,%ebp
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     121e <build_argv+0xde>
mov    $0x2,%ebx
xchg   %ax,%ax
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1200 <build_argv+0xc0>
mov    (%rsp),%rax
mov    %ebx,(%rax)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/heads/master/lib/gpm/src/gpm.c\00"
@.str.1 = [19 x i8] c"allocation failed!\00"
define i8** @build_argv(i8* %0, i8* %1, i32* %2, i8 signext %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i8 %3, i8* %9
store i32 1, i32* %10
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %35
15: ; preds = %4
%16 = load i8*, i8** %7
store i8* %16, i8** %12
br label %17
17: ; preds = %31, %15
%18 = load i8, i8* %9
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8*, i8** %12
%23 = load i8, i8* %9
%24 = call i8* @strchr(i8* %22, i8 signext %23)
store i8* %24, i8** %12
%25 = icmp ne i8* %24, null
br label %26
26: ; preds = %21, %17
%27 = phi i1 [ false, %17 ], [ %25, %21 ]
br i1 %27, label %28, label %34
28: ; preds = %26
%29 = load i8*, i8** %12
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %12
br label %31
31: ; preds = %28
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %17
34: ; preds = %26
br label %35
35: ; preds = %34, %4
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 2
%38 = call i8** @calloc(i32 %37, i32 8)
store i8** %38, i8*** %11
%39 = load i8**, i8*** %11
%40 = icmp ne i8** %39, null
br i1 %40, label %43, label %41
41: ; preds = %35
%42 = call i32 @gpm_report(i32 125, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = load i8*, i8** %6
%45 = load i8**, i8*** %11
%46 = getelementptr inbounds i8*, i8** %45, i64 0
store i8* %44, i8** %46
%47 = load i8*, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %53, label %49
49: ; preds = %43
%50 = load i32, i32* %10
%51 = load i32*, i32** %8
store i32 %50, i32* %51
%52 = load i8**, i8*** %11
store i8** %52, i8*** %5
br label %85
53: ; preds = %43
%54 = load i8*, i8** %7
%55 = call i8* @strdup(i8* %54)
%56 = load i8**, i8*** %11
%57 = getelementptr inbounds i8*, i8** %56, i64 1
store i8* %55, i8** %57
store i8* %55, i8** %12
store i32 2, i32* %10
br label %58
58: ; preds = %78, %53
%59 = load i8, i8* %9
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i8*, i8** %12
%64 = load i8, i8* %9
%65 = call i8* @strchr(i8* %63, i8 signext %64)
store i8* %65, i8** %12
%66 = icmp ne i8* %65, null
br label %67
67: ; preds = %62, %58
%68 = phi i1 [ false, %58 ], [ %66, %62 ]
br i1 %68, label %69, label %81
69: ; preds = %67
%70 = load i8*, i8** %12
store i8 0, i8* %70
%71 = load i8*, i8** %12
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %12
%73 = load i8*, i8** %12
%74 = load i8**, i8*** %11
%75 = load i32, i32* %10
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
store i8* %73, i8** %77
br label %78
78: ; preds = %69
%79 = load i32, i32* %10
%80 = add nsw i32 %79, 1
store i32 %80, i32* %10
br label %58
81: ; preds = %67
%82 = load i32, i32* %10
%83 = load i32*, i32** %8
store i32 %82, i32* %83
%84 = load i8**, i8*** %11
store i8** %84, i8*** %5
br label %85
85: ; preds = %81, %49
%86 = load i8**, i8*** %5
ret i8** %86
}

LLVM IR (-O2):
@.str = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/heads/master/lib/gpm/src/gpm.c\00"
@.str.1 = [19 x i8] c"allocation failed!\00"
define noalias i8** @build_argv(i8* %0, i8* %1, i32* nocapture writeonly %2, i8 signext %3) {
%5 = icmp eq i8* %1, null
%6 = icmp eq i8 %3, 0
%7 = or i1 %5, %6
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = tail call i8* @strchr(i8* %1, i8 signext %3)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %8, %11
%12 = phi i8* [ %16, %11 ], [ %9, %8 ]
%13 = phi i32 [ %15, %11 ], [ 1, %8 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = add nuw nsw i32 %13, 1
%16 = tail call i8* @strchr(i8* %14, i8 signext %3)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %11
18: ; preds = %11, %8, %4
%19 = phi i32 [ 1, %4 ], [ 1, %8 ], [ %15, %11 ]
%20 = add nuw nsw i32 %19, 2
%21 = tail call i8** @calloc(i32 %20, i32 8)
%22 = icmp eq i8** %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @gpm_report(i32 125, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
store i8* %0, i8** %21
br i1 %5, label %43, label %26
26: ; preds = %25
%27 = tail call i8* @strdup(i8* %1)
%28 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* %27, i8** %28
%29 = icmp eq i8 %3, 0
br i1 %29, label %43, label %30
30: ; preds = %26
%31 = tail call i8* @strchr(i8* dereferenceable(1) %27, i8 signext %3)
%32 = icmp eq i8* %31, null
br i1 %32, label %43, label %33
33: ; preds = %30, %33
%34 = phi i8* [ %39, %33 ], [ %31, %30 ]
%35 = phi i64 [ %38, %33 ], [ 2, %30 ]
store i8 0, i8* %34
%36 = getelementptr inbounds i8, i8* %34, i64 1
%37 = getelementptr inbounds i8*, i8** %21, i64 %35
store i8* %36, i8** %37
%38 = add nuw i64 %35, 1
%39 = tail call i8* @strchr(i8* dereferenceable(1) %36, i8 signext %3)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %33
41: ; preds = %33
%42 = trunc i64 %38 to i32
br label %43
43: ; preds = %30, %41, %26, %25
%44 = phi i32 [ %19, %25 ], [ 2, %26 ], [ %42, %41 ], [ 2, %30 ]
store i32 %44, i32* %2
ret i8** %21
}