#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 */
scalar_t__ check_words(char, char const *);
int /*<<< orphan*/ exit(int);
char **malloc(int);
int init_buffer(char *str, const char *delim, char ***tab) {
  int i;
  int argss;
  i = 0;
  argss = 2;
  while (str[i] != 0) {
    if (check_words(str[i], delim) == 0)
      argss = argss + 1;
    i++;
  }
  if ((*tab = malloc(sizeof(char *) * argss)) == NULL)
    exit(-1);
  return (argss);
}


x86 assembly (clang, -O0):
<init_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119f <init_buffer+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <check_words@plt>
cmp    $0x0,%rax
jne    1191 <init_buffer+0x61>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <init_buffer+0x22>
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11c9 <init_buffer+0x99>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    (%rdi),%al
test   %al,%al
je     1180 <init_buffer+0x50>
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0x2,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r15,%rsi
call   1030 <check_words@plt>
cmp    $0x1,%rax
adc    $0x0,%r12d
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <init_buffer+0x30>
jmp    1186 <init_buffer+0x56>
mov    $0x2,%r12d
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11aa <init_buffer+0x7a>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define i32 @init_buffer(i8* %0, i8* %1, i8*** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8***
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8*** %2, i8**** %6
store i32 0, i32* %7
store i32 2, i32* %8
br label %9
9: ; preds = %29, %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %5
%24 = call i64 @check_words(i8 signext %22, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %29
29: ; preds = %26, %17
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %9
32: ; preds = %9
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = mul i64 8, %34
%36 = trunc i64 %35 to i32
%37 = call i8** @malloc(i32 %36)
%38 = load i8***, i8**** %6
store i8** %37, i8*** %38
%39 = icmp eq i8** %37, null
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %32
%43 = load i32, i32* %8
ret i32 %43
}

LLVM IR (-O2):
define i32 @init_buffer(i8* nocapture %0, i8* %1, i8*** nocapture writeonly %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %14, %6 ], [ 0, %3 ]
%8 = phi i8 [ %16, %6 ], [ %4, %3 ]
%9 = phi i32 [ %13, %6 ], [ 2, %3 ]
%10 = tail call i64 @check_words(i8 signext %8, i8* %1)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %9, %12
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %3
%19 = phi i32 [ 2, %3 ], [ %13, %6 ]
%20 = shl i32 %19, 3
%21 = tail call i8** @malloc(i32 %20)
store i8** %21, i8*** %2
%22 = icmp eq i8** %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %18
ret i32 %19
}