#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, char *, int);
char *get_line_word(char *, char **);
char **malloc(int);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int copy_strarr(void *d, char *next) {
  char ***sd = (char ***)d;
  char *v;
  char *tmp = next;
  char **p;
  int i;
  int n = 0;
  while ((v = get_line_word(next, &next))) {
    n++;
  }
  if (n < 1)
    return 1;
  {
    if ((p = malloc((n + 1) * sizeof(*p))) == NULL) {
      {
        fprintf(stderr, "Malloc of %ld failed at %s:%d\n", (size_t)(n + 1),
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/heckendorfc/newsbaoter/refs/"
                "heads/master/src/config.c",
                64);
        exit(22);
      };
    }
  };
  v = tmp;
  for (i = 0; i < n; i++) {
    p[i] = strdup(v);
    while (*(v++))
      ;
  }
  p[n] = NULL;
  *sd = p;
  return 0;
}


x86 assembly (clang, -O0):
<copy_strarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <get_line_word@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11a0 <copy_strarr+0x50>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1177 <copy_strarr+0x27>
cmpl   $0x1,-0x40(%rbp)
jge    11b6 <copy_strarr+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1291 <copy_strarr+0x141>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    120c <copy_strarr+0xbc>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdx
lea    0xe10(%rip),%rsi
lea    0xe28(%rip),%rcx
mov    $0x40,%r8d
call   1040 <fprintf@plt>
mov    $0x16,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    126f <copy_strarr+0x11f>
mov    -0x28(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
cmpb   $0x0,(%rax)
je     125c <copy_strarr+0x10c>
jmp    123f <copy_strarr+0xef>
jmp    1261 <copy_strarr+0x111>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    121b <copy_strarr+0xcb>
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_strarr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <get_line_word@plt>
mov    $0x1,%r15d
xor    %ebp,%ebp
test   %rax,%rax
je     11af <copy_strarr+0x5f>
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1030 <get_line_word@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1190 <copy_strarr+0x40>
lea    0x1(%rbp),%r12d
test   %ebp,%ebp
jne    11b9 <copy_strarr+0x69>
jmp    1210 <copy_strarr+0xc0>
mov    $0x1,%r12d
test   %ebp,%ebp
je     1210 <copy_strarr+0xc0>
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1220 <copy_strarr+0xd0>
mov    %rax,%r15
mov    %ebp,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r15,%rbp,8)
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    11f0 <copy_strarr+0xa0>
add    $0x1,%rbp
cmp    %r12,%rbp
jne    11e0 <copy_strarr+0x90>
movq   $0x0,(%r15,%r12,8)
mov    %r15,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,%edx
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
lea    0xde5(%rip),%rcx
mov    $0x40,%r8d
call   1040 <fprintf@plt>
mov    $0x16,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Malloc of %ld failed at %s:%d\0A\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/heckendorfc/newsbaoter/refs/heads/master/src/config.c\00"
define i32 @copy_strarr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8***
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to i8***
store i8*** %13, i8**** %6
%14 = load i8*, i8** %5
store i8* %14, i8** %8
store i32 0, i32* %11
br label %15
15: ; preds = %19, %2
%16 = load i8*, i8** %5
%17 = call i8* @get_line_word(i8* %16, i8** %5)
store i8* %17, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %11
%21 = add nsw i32 %20, 1
store i32 %21, i32* %11
br label %15
22: ; preds = %15
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %3
br label %71
26: ; preds = %22
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i8** @malloc(i32 %31)
store i8** %32, i8*** %9
%33 = icmp eq i8** %32, null
br i1 %33, label %34, label %41
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %38, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 64)
%40 = call i32 @exit(i32 22)
unreachable
41: ; preds = %26
%42 = load i8*, i8** %8
store i8* %42, i8** %7
store i32 0, i32* %10
br label %43
43: ; preds = %61, %41
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %64
47: ; preds = %43
%48 = load i8*, i8** %7
%49 = call i8* @strdup(i8* %48)
%50 = load i8**, i8*** %9
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
store i8* %49, i8** %53
br label %54
54: ; preds = %59, %47
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %7
%57 = load i8, i8* %55
%58 = icmp ne i8 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
br label %54
60: ; preds = %54
br label %61
61: ; preds = %60
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %43
64: ; preds = %43
%65 = load i8**, i8*** %9
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
store i8* null, i8** %68
%69 = load i8**, i8*** %9
%70 = load i8***, i8**** %6
store i8** %69, i8*** %70
store i32 0, i32* %3
br label %71
71: ; preds = %64, %25
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Malloc of %ld failed at %s:%d\0A\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/heckendorfc/newsbaoter/refs/heads/master/src/config.c\00"
define i32 @copy_strarr(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
store i8* %1, i8** %3
%4 = call i8* @get_line_word(i8* %1, i8** %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %11, %6 ], [ 1, %2 ]
%8 = load i8*, i8** %3
%9 = call i8* @get_line_word(i8* %8, i8** %3)
%10 = icmp eq i8* %9, null
%11 = add nuw nsw i32 %7, 1
br i1 %10, label %12, label %6
12: ; preds = %6, %2
%13 = phi i32 [ 0, %2 ], [ %7, %6 ]
%14 = phi i32 [ 1, %2 ], [ %11, %6 ]
%15 = bitcast i8* %0 to i8***
%16 = icmp eq i32 %13, 0
br i1 %16, label %43, label %17
17: ; preds = %12
%18 = shl i32 %14, 3
%19 = call i8** @malloc(i32 %18)
%20 = icmp eq i8** %19, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = zext i32 %13 to i64
br label %28
23: ; preds = %17
%24 = zext i32 %14 to i64
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %24, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 64)
%27 = call i32 @exit(i32 22)
unreachable
28: ; preds = %21, %38
%29 = phi i64 [ 0, %21 ], [ %39, %38 ]
%30 = phi i8* [ %1, %21 ], [ %35, %38 ]
%31 = call i8* @strdup(i8* %30)
%32 = getelementptr inbounds i8*, i8** %19, i64 %29
store i8* %31, i8** %32
br label %33
33: ; preds = %33, %28
%34 = phi i8* [ %30, %28 ], [ %35, %33 ]
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %34
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %33
38: ; preds = %33
%39 = add nuw nsw i64 %29, 1
%40 = icmp eq i64 %39, %22
br i1 %40, label %41, label %28
41: ; preds = %38
%42 = getelementptr inbounds i8*, i8** %19, i64 %22
store i8* null, i8** %42
store i8** %19, i8*** %15
br label %43
43: ; preds = %12, %41
%44 = phi i32 [ 0, %41 ], [ 1, %12 ]
ret i32 %44
}