#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 countSmallOpts(int, char **);
scalar_t__ malloc(int);
int optType(char *const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *const, char *);
int /*<<< orphan*/ strcpy(char *const, char *);
int strlen(char *const);
int buildOptLists(int argc, char *argv[], char **smallOpts, char **longOpts[]) {
  *smallOpts = (char *)malloc(countSmallOpts(argc, argv) + 1);
  char *const smallPtr = *smallOpts;
  if (!smallPtr) {
    printf("Allocation error, quitting.\n");
    return 1;
  }
  smallPtr[0] = '\0';
  *longOpts = (char **)malloc(sizeof(char *) * argc);
  char **longPtr = *longOpts;
  if (!longPtr) {
    printf("Malloc error, quitting.\n");
    return 1;
  }
  longPtr[0] = NULL;
  int longCount = 0;
  for (int i = 2; i < argc; i++) {
    char *const curArg = argv[i];
    const int type = optType(curArg);
    if (type == 1) {
      char *const longOpt = (char *)malloc(strlen(curArg) - 1);
      strcpy(longOpt, &curArg[2]);
      longPtr[longCount] = longOpt;
      longPtr[longCount + 1] = NULL;
      longCount++;
    } else if (type == 0) {
      strcat(smallPtr, &curArg[1]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<buildOptLists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <countSmallOpts@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d5 <buildOptLists+0x65>
lea    0xe3c(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1303 <buildOptLists+0x193>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1223 <buildOptLists+0xb3>
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1303 <buildOptLists+0x193>
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x34(%rbp)
movl   $0x2,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12fc <buildOptLists+0x18c>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1080 <optType@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jne    12c9 <buildOptLists+0x159>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
sub    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x2,%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12e9 <buildOptLists+0x179>
cmpl   $0x0,-0x44(%rbp)
jne    12e4 <buildOptLists+0x174>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x1,%rsi
call   1090 <strcat@plt>
jmp    12e9 <buildOptLists+0x179>
jmp    12ee <buildOptLists+0x17e>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    123c <buildOptLists+0xcc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildOptLists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %edi,%r12d
call   1050 <countSmallOpts@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     126b <buildOptLists+0xfb>
mov    %rax,%rbp
movb   $0x0,(%rax)
lea    0x0(,%r12,8),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1274 <buildOptLists+0x104>
mov    %rax,%r15
movq   $0x0,(%rax)
xor    %eax,%eax
cmp    $0x3,%r12d
jl     1289 <buildOptLists+0x119>
mov    %rbp,0x10(%rsp)
mov    %r12d,%r12d
xor    %ebp,%ebp
mov    $0x2,%r14d
mov    %r12,0x8(%rsp)
jmp    120a <buildOptLists+0x9a>
nop
add    $0x1,%rbx
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
add    $0x1,%r14
cmp    %r14,%r12
je     1287 <buildOptLists+0x117>
mov    0x0(%r13,%r14,8),%rbx
mov    %rbx,%rdi
call   1080 <optType@plt>
test   %eax,%eax
je     11f0 <buildOptLists+0x80>
cmp    $0x1,%eax
jne    1201 <buildOptLists+0x91>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %r13,%r12
mov    %r15,%r13
mov    %ebp,%r15d
mov    %rax,%rbp
add    $0x2,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movslq %r15d,%rax
mov    %r13,%r15
mov    %r12,%r13
mov    0x8(%rsp),%r12
mov    %rbp,(%r15,%rax,8)
lea    0x1(%rax),%ebp
movq   $0x0,0x8(%r15,%rax,8)
jmp    1201 <buildOptLists+0x91>
lea    0xd8e(%rip),%rdi
jmp    127b <buildOptLists+0x10b>
lea    0xda1(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1289 <buildOptLists+0x119>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Allocation error, quitting.\0A\00"
@.str.1 = [25 x i8] c"Malloc error, quitting.\0A\00"
define i32 @buildOptLists(i32 %0, i8** %1, i8** %2, i8*** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8***
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8*** %3, i8**** %9
%17 = load i32, i32* %6
%18 = load i8**, i8*** %7
%19 = call i32 @countSmallOpts(i32 %17, i8** %18)
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = load i8**, i8*** %8
store i8* %22, i8** %23
%24 = load i8**, i8*** %8
%25 = load i8*, i8** %24
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = icmp ne i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %4
%29 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %99
30: ; preds = %4
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 0, i8* %32
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = mul i64 8, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8**
%39 = load i8***, i8**** %9
store i8** %38, i8*** %39
%40 = load i8***, i8**** %9
%41 = load i8**, i8*** %40
store i8** %41, i8*** %11
%42 = load i8**, i8*** %11
%43 = icmp ne i8** %42, null
br i1 %43, label %46, label %44
44: ; preds = %30
%45 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %5
br label %99
46: ; preds = %30
%47 = load i8**, i8*** %11
%48 = getelementptr inbounds i8*, i8** %47, i64 0
store i8* null, i8** %48
store i32 0, i32* %12
store i32 2, i32* %13
br label %49
49: ; preds = %95, %46
%50 = load i32, i32* %13
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %98
53: ; preds = %49
%54 = load i8**, i8*** %7
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
store i8* %58, i8** %14
%59 = load i8*, i8** %14
%60 = call i32 @optType(i8* %59)
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %85
63: ; preds = %53
%64 = load i8*, i8** %14
%65 = call i32 @strlen(i8* %64)
%66 = sub nsw i32 %65, 1
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to i8*
store i8* %68, i8** %16
%69 = load i8*, i8** %16
%70 = load i8*, i8** %14
%71 = getelementptr inbounds i8, i8* %70, i64 2
%72 = call i32 @strcpy(i8* %69, i8* %71)
%73 = load i8*, i8** %16
%74 = load i8**, i8*** %11
%75 = load i32, i32* %12
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
store i8* %73, i8** %77
%78 = load i8**, i8*** %11
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %78, i64 %81
store i8* null, i8** %82
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
br label %94
85: ; preds = %53
%86 = load i32, i32* %15
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %85
%89 = load i8*, i8** %10
%90 = load i8*, i8** %14
%91 = getelementptr inbounds i8, i8* %90, i64 1
%92 = call i32 @strcat(i8* %89, i8* %91)
br label %93
93: ; preds = %88, %85
br label %94
94: ; preds = %93, %63
br label %95
95: ; preds = %94
%96 = load i32, i32* %13
%97 = add nsw i32 %96, 1
store i32 %97, i32* %13
br label %49
98: ; preds = %49
store i32 0, i32* %5
br label %99
99: ; preds = %98, %44, %28
%100 = load i32, i32* %5
ret i32 %100
}

LLVM IR (-O2):
@str = [28 x i8] c"Allocation error, quitting.\00"
@str.2 = [24 x i8] c"Malloc error, quitting.\00"
define i32 @buildOptLists(i32 %0, i8** %1, i8** nocapture writeonly %2, i8*** nocapture writeonly %3) {
%5 = tail call i32 @countSmallOpts(i32 %0, i8** %1)
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = icmp eq i64 %7, 0
br i1 %9, label %44, label %10
10: ; preds = %4
store i8 0, i8* %8
%11 = shl i32 %0, 3
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %3
%14 = icmp eq i64 %12, 0
br i1 %14, label %44, label %15
15: ; preds = %10
store i8* null, i8** %13
%16 = icmp sgt i32 %0, 2
br i1 %16, label %17, label %47
17: ; preds = %15
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %17, %40
%20 = phi i64 [ 2, %17 ], [ %42, %40 ]
%21 = phi i32 [ 0, %17 ], [ %41, %40 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %20
%23 = load i8*, i8** %22
%24 = tail call i32 @optType(i8* %23)
switch i32 %24, label %40 [
i32 1, label %25
i32 0, label %37
]
25: ; preds = %19
%26 = tail call i32 @strlen(i8* %23)
%27 = add nsw i32 %26, -1
%28 = tail call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = getelementptr inbounds i8, i8* %23, i64 2
%31 = tail call i32 @strcpy(i8* %29, i8* %30)
%32 = sext i32 %21 to i64
%33 = getelementptr inbounds i8*, i8** %13, i64 %32
store i8* %29, i8** %33
%34 = add nsw i32 %21, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %13, i64 %35
store i8* null, i8** %36
br label %40
37: ; preds = %19
%38 = getelementptr inbounds i8, i8* %23, i64 1
%39 = tail call i32 @strcat(i8* %8, i8* %38)
br label %40
40: ; preds = %19, %37, %25
%41 = phi i32 [ %34, %25 ], [ %21, %37 ], [ %21, %19 ]
%42 = add nuw nsw i64 %20, 1
%43 = icmp eq i64 %42, %18
br i1 %43, label %47, label %19
44: ; preds = %10, %4
%45 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.2, i64 0, i64 0), %10 ]
%46 = tail call i32 @puts(i8* dereferenceable(1) %45)
br label %47
47: ; preds = %40, %44, %15
%48 = phi i32 [ 0, %15 ], [ 1, %44 ], [ 0, %40 ]
ret i32 %48
}