#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 */
struct quoting_options {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(struct slotvec *, int /*<<< orphan*/, unsigned int);
size_t quotearg_buffer(char *, size_t, char const *, size_t,
                       struct quoting_options const *);
int /*<<< orphan*/ xalloc_die();
scalar_t__ xalloc_oversized(int, int);
void *xmalloc(size_t);
struct slotvec *xrealloc(struct slotvec *, unsigned int);
char *quotearg_n_options(int n, char const *arg, size_t argsize,
                         struct quoting_options const *options) {
  int e = errno;
  static char slot0[256];
  static unsigned int nslots = 1;
  unsigned int n0 = n;
  struct slotvec {
    size_t size;
    char *val;
  };
  static struct slotvec slotvec0 = {sizeof slot0, slot0};
  static struct slotvec *slotvec = &slotvec0;
  if (n < 0)
    abort();
  if (nslots <= n0) {
    unsigned int n1 = n0 + 1;
    if (xalloc_oversized((int)n1, sizeof *slotvec))
      xalloc_die();
    if (slotvec == &slotvec0) {
      slotvec = xmalloc(sizeof *slotvec);
      *slotvec = slotvec0;
    }
    slotvec = xrealloc(slotvec, n1 * sizeof *slotvec);
    memset(slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);
    nslots = n1;
  }
  {
    size_t size = slotvec[n].size;
    char *val = slotvec[n].val;
    size_t qsize = quotearg_buffer(val, size, arg, argsize, options);
    if (size <= qsize) {
      slotvec[n].size = size = qsize + 1;
      if (val != slot0)
        free(val);
      slotvec[n].val = val = xmalloc(size);
      quotearg_buffer(val, size, arg, argsize, options);
    }
    errno = e;
    return val;
  }
}


x86 assembly (clang, -O0):
<quotearg_n_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11ba <quotearg_n_options+0x3a>
mov    $0x0,%al
call   1040 <abort@plt>
mov    0x2ea0(%rip),%eax
cmp    -0x28(%rbp),%eax
ja     1282 <quotearg_n_options+0x102>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x10,%esi
call   1070 <xalloc_oversized@plt>
cmp    $0x0,%rax
je     11f0 <quotearg_n_options+0x70>
mov    $0x0,%al
call   10a0 <xalloc_die@plt>
lea    0x2e71(%rip),%rax
cmp    %rax,0x2e7a(%rip)
jne    1231 <quotearg_n_options+0xb1>
mov    $0x10,%edi
call   1090 <xmalloc@plt>
mov    %rax,0x2e63(%rip)
mov    0x2e5c(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    %rcx,(%rax)
mov    0x2e43(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    0x2e40(%rip),%rdi
mov    -0x2c(%rbp),%eax
shl    $0x4,%rax
mov    %eax,%esi
call   1060 <xrealloc@plt>
mov    %rax,0x2e2b(%rip)
mov    0x2e24(%rip),%rdi
mov    0x2e06(%rip),%eax
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x2c(%rbp),%eax
sub    0x2df6(%rip),%eax
mov    %eax,%eax
shl    $0x4,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,0x2dde(%rip)
mov    0x2def(%rip),%rax
movslq -0x4(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dd6(%rip),%rax
movslq -0x4(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1050 <quotearg_buffer@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
ja     135a <quotearg_n_options+0x1da>
mov    -0x48(%rbp),%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    0x2d85(%rip),%rax
movslq -0x4(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
lea    0x2d98(%rip),%rax
cmp    %rax,-0x40(%rbp)
je     131b <quotearg_n_options+0x19b>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1090 <xmalloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    0x2d46(%rip),%rax
movslq -0x4(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1050 <quotearg_buffer@plt>
mov    -0x24(%rbp),%ecx
mov    0x2c7c(%rip),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quotearg_n_options>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
js     12f4 <quotearg_n_options+0x174>
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
cmp    %edi,0x2eac(%rip)
ja     123e <quotearg_n_options+0xbe>
mov    %rbp,%r14
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
mov    $0x10,%esi
call   1070 <xalloc_oversized@plt>
test   %rax,%rax
je     11d8 <quotearg_n_options+0x58>
xor    %eax,%eax
call   10a0 <xalloc_die@plt>
mov    0x2e99(%rip),%rdi
lea    0x2e82(%rip),%rax
cmp    %rax,%rdi
jne    1209 <quotearg_n_options+0x89>
mov    $0x10,%edi
call   1090 <xmalloc@plt>
mov    %rax,%rdi
mov    %rax,0x2e79(%rip)
movups 0x2e62(%rip),%xmm0
movups %xmm0,(%rax)
mov    %ebp,%esi
shl    $0x4,%esi
call   1060 <xrealloc@plt>
mov    %rax,0x2e5e(%rip)
mov    0x2e40(%rip),%edi
mov    %ebp,%edx
sub    %edi,%edx
shl    $0x4,%rdi
add    %rax,%rdi
shl    $0x4,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    %ebp,0x2e25(%rip)
mov    %r14,%rbp
mov    0x2e33(%rip),%rax
mov    %ebx,%r14d
shl    $0x4,%r14
mov    (%rax,%r14,1),%rbx
mov    0x8(%rax,%r14,1),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,0x10(%rsp)
mov    %r12,%rdx
mov    %r15,%r12
mov    %r15,%rcx
mov    %rbp,%r15
mov    %rbp,%r8
call   1050 <quotearg_buffer@plt>
cmp    %rax,%rbx
jbe    1282 <quotearg_n_options+0x102>
mov    0x2d60(%rip),%rbx
jmp    12dc <quotearg_n_options+0x15c>
mov    %rax,%rbp
add    $0x1,%rbp
mov    0x2de8(%rip),%rax
mov    %rbp,(%rax,%r14,1)
lea    0x2e05(%rip),%rax
cmp    %rax,%r13
mov    0x2d3b(%rip),%rbx
je     12af <quotearg_n_options+0x12f>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1090 <xmalloc@plt>
mov    %rax,%r13
mov    0x2db7(%rip),%rax
mov    %r13,0x8(%rax,%r14,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rdx
mov    %r12,%rcx
mov    %r15,%r8
call   1050 <quotearg_buffer@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.slotvec = type { i64, i8* }
%struct.quoting_options = type { i32 }
%struct.slotvec.0 = type opaque
%struct.slotvec.1 = type opaque
@errno = global i32 0
@quotearg_n_options.slot0 = internal global [256 x i8] zeroinitializer
@quotearg_n_options.nslots = internal global i32 1
@quotearg_n_options.slotvec0 = internal global %struct.slotvec { i64 256, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @quotearg_n_options.slot0, i32 0, i32 0) }
@quotearg_n_options.slotvec = internal global %struct.slotvec* @quotearg_n_options.slotvec0
define i8* @quotearg_n_options(i32 %0, i8* %1, i64 %2, %struct.quoting_options* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.quoting_options*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store %struct.quoting_options* %3, %struct.quoting_options** %8
%15 = load i32, i32* @errno
store i32 %15, i32* %9
%16 = load i32, i32* %5
store i32 %16, i32* %10
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %4
%22 = load i32, i32* @quotearg_n_options.nslots
%23 = load i32, i32* %10
%24 = icmp ule i32 %22, %23
br i1 %24, label %25, label %63
25: ; preds = %21
%26 = load i32, i32* %10
%27 = add i32 %26, 1
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = call i64 @xalloc_oversized(i32 %28, i32 16)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (...) @xalloc_die()
br label %33
33: ; preds = %31, %25
%34 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%35 = icmp eq %struct.slotvec* %34, @quotearg_n_options.slotvec0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = call i8* @xmalloc(i64 16)
%38 = bitcast i8* %37 to %struct.slotvec*
store %struct.slotvec* %38, %struct.slotvec** @quotearg_n_options.slotvec
%39 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%40 = bitcast %struct.slotvec* %39 to i8*
br label %41
41: ; preds = %36, %33
%42 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%43 = bitcast %struct.slotvec* %42 to %struct.slotvec.0*
%44 = load i32, i32* %11
%45 = zext i32 %44 to i64
%46 = mul i64 %45, 16
%47 = trunc i64 %46 to i32
%48 = call %struct.slotvec.0* @xrealloc(%struct.slotvec.0* %43, i32 %47)
%49 = bitcast %struct.slotvec.0* %48 to %struct.slotvec*
store %struct.slotvec* %49, %struct.slotvec** @quotearg_n_options.slotvec
%50 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%51 = load i32, i32* @quotearg_n_options.nslots
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %50, i64 %52
%54 = bitcast %struct.slotvec* %53 to %struct.slotvec.1*
%55 = load i32, i32* %11
%56 = load i32, i32* @quotearg_n_options.nslots
%57 = sub i32 %55, %56
%58 = zext i32 %57 to i64
%59 = mul i64 %58, 16
%60 = trunc i64 %59 to i32
%61 = call i32 @memset(%struct.slotvec.1* %54, i32 0, i32 %60)
%62 = load i32, i32* %11
store i32 %62, i32* @quotearg_n_options.nslots
br label %63
63: ; preds = %41, %21
%64 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %64, i64 %66
%68 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %67, i32 0, i32 0
%69 = load i64, i64* %68
store i64 %69, i64* %12
%70 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %70, i64 %72
%74 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %73, i32 0, i32 1
%75 = load i8*, i8** %74
store i8* %75, i8** %13
%76 = load i8*, i8** %13
%77 = load i64, i64* %12
%78 = load i8*, i8** %6
%79 = load i64, i64* %7
%80 = load %struct.quoting_options*, %struct.quoting_options** %8
%81 = call i64 @quotearg_buffer(i8* %76, i64 %77, i8* %78, i64 %79, %struct.quoting_options* %80)
store i64 %81, i64* %14
%82 = load i64, i64* %12
%83 = load i64, i64* %14
%84 = icmp ule i64 %82, %83
br i1 %84, label %85, label %112
85: ; preds = %63
%86 = load i64, i64* %14
%87 = add i64 %86, 1
store i64 %87, i64* %12
%88 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%89 = load i32, i32* %5
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %88, i64 %90
%92 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %91, i32 0, i32 0
store i64 %87, i64* %92
%93 = load i8*, i8** %13
%94 = icmp ne i8* %93, getelementptr inbounds ([256 x i8], [256 x i8]* @quotearg_n_options.slot0, i64 0, i64 0)
br i1 %94, label %95, label %98
95: ; preds = %85
%96 = load i8*, i8** %13
%97 = call i32 @free(i8* %96)
br label %98
98: ; preds = %95, %85
%99 = load i64, i64* %12
%100 = call i8* @xmalloc(i64 %99)
store i8* %100, i8** %13
%101 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%102 = load i32, i32* %5
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %101, i64 %103
%105 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %104, i32 0, i32 1
store i8* %100, i8** %105
%106 = load i8*, i8** %13
%107 = load i64, i64* %12
%108 = load i8*, i8** %6
%109 = load i64, i64* %7
%110 = load %struct.quoting_options*, %struct.quoting_options** %8
%111 = call i64 @quotearg_buffer(i8* %106, i64 %107, i8* %108, i64 %109, %struct.quoting_options* %110)
br label %112
112: ; preds = %98, %63
%113 = load i32, i32* %9
store i32 %113, i32* @errno
%114 = load i8*, i8** %13
ret i8* %114
}

LLVM IR (-O2):
%struct.slotvec = type { i64, i8* }
%struct.quoting_options = type { i32 }
%struct.slotvec.0 = type opaque
%struct.slotvec.1 = type opaque
@errno = global i32 0
@quotearg_n_options.slot0 = internal global [256 x i8] zeroinitializer
@quotearg_n_options.nslots = internal unnamed_addr global i32 1
@quotearg_n_options.slotvec0 = internal global %struct.slotvec { i64 256, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @quotearg_n_options.slot0, i32 0, i32 0) }
@quotearg_n_options.slotvec = internal unnamed_addr global %struct.slotvec* @quotearg_n_options.slotvec0
define i8* @quotearg_n_options(i32 %0, i8* %1, i64 %2, %struct.quoting_options* %3) {
%5 = load i32, i32* @errno
%6 = icmp slt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %4
%10 = load i32, i32* @quotearg_n_options.nslots
%11 = icmp ugt i32 %10, %0
br i1 %11, label %37, label %12
12: ; preds = %9
%13 = add nuw i32 %0, 1
%14 = tail call i64 @xalloc_oversized(i32 %13, i32 16)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 (...) @xalloc_die()
br label %18
18: ; preds = %16, %12
%19 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%20 = icmp eq %struct.slotvec* %19, @quotearg_n_options.slotvec0
%21 = bitcast %struct.slotvec* %19 to %struct.slotvec.0*
br i1 %20, label %22, label %25
22: ; preds = %18
%23 = tail call i8* @xmalloc(i64 16)
store i8* %23, i8** bitcast (%struct.slotvec** @quotearg_n_options.slotvec to i8**)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(16) %23, i8* align 8 dereferenceable(16) bitcast (%struct.slotvec* @quotearg_n_options.slotvec0 to i8*), i64 16, i1 false)
%24 = bitcast i8* %23 to %struct.slotvec.0*
br label %25
25: ; preds = %22, %18
%26 = phi %struct.slotvec.0* [ %24, %22 ], [ %21, %18 ]
%27 = shl i32 %13, 4
%28 = tail call %struct.slotvec.0* @xrealloc(%struct.slotvec.0* %26, i32 %27)
%29 = bitcast %struct.slotvec.0* %28 to %struct.slotvec*
store %struct.slotvec.0* %28, %struct.slotvec.0** bitcast (%struct.slotvec** @quotearg_n_options.slotvec to %struct.slotvec.0**)
%30 = load i32, i32* @quotearg_n_options.nslots
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %29, i64 %31
%33 = bitcast %struct.slotvec* %32 to %struct.slotvec.1*
%34 = sub i32 %13, %30
%35 = shl i32 %34, 4
%36 = tail call i32 @memset(%struct.slotvec.1* %33, i32 0, i32 %35)
store i32 %13, i32* @quotearg_n_options.nslots
br label %37
37: ; preds = %25, %9
%38 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%39 = zext i32 %0 to i64
%40 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %38, i64 %39, i32 0
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %38, i64 %39, i32 1
%43 = load i8*, i8** %42
%44 = tail call i64 @quotearg_buffer(i8* %43, i64 %41, i8* %1, i64 %2, %struct.quoting_options* %3)
%45 = icmp ugt i64 %41, %44
br i1 %45, label %58, label %46
46: ; preds = %37
%47 = add i64 %44, 1
%48 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%49 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %48, i64 %39, i32 0
store i64 %47, i64* %49
%50 = icmp eq i8* %43, getelementptr inbounds ([256 x i8], [256 x i8]* @quotearg_n_options.slot0, i64 0, i64 0)
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = tail call i32 @free(i8* %43)
br label %53
53: ; preds = %51, %46
%54 = tail call i8* @xmalloc(i64 %47)
%55 = load %struct.slotvec*, %struct.slotvec** @quotearg_n_options.slotvec
%56 = getelementptr inbounds %struct.slotvec, %struct.slotvec* %55, i64 %39, i32 1
store i8* %54, i8** %56
%57 = tail call i64 @quotearg_buffer(i8* %54, i64 %47, i8* %1, i64 %2, %struct.quoting_options* %3)
br label %58
58: ; preds = %53, %37
%59 = phi i8* [ %54, %53 ], [ %43, %37 ]
store i32 %5, i32* @errno
ret i8* %59
}