#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 */
typedef int /*<<< orphan*/ va_list;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
scalar_t__ vasprintf(char **, char const *, int /*<<< orphan*/);
int vexpect_decode(char const *, char const *, int, char *);
int vexpect(const char *expected, const char *text, int ty, const char *fmt,
            va_list ap) {
  char *str = NULL;
  int ret;
  if (vasprintf(&str, fmt, ap) < 0) {
    fprintf(stderr, "error: vasprintf failed: %s\n", text);
    return -1;
  }
  ret = vexpect_decode(expected, text, ty, str);
  free(str);
  return ret;
}


x86 assembly (clang, -O0):
<vexpect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x38(%rbp),%rdi
call   1040 <vasprintf@plt>
cmp    $0x0,%rax
jge    11a2 <vexpect+0x62>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <vexpect+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1060 <vexpect_decode@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vexpect>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %rcx,%rsi
mov    %r8d,%edx
call   1040 <vasprintf@plt>
test   %rax,%rax
js     1190 <vexpect+0x50>
mov    0x8(%rsp),%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <vexpect_decode@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    11ad <vexpect+0x6d>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"error: vasprintf failed: %s\0A\00"
define i32 @vexpect(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* null, i8** %12
%14 = load i8*, i8** %10
%15 = load i32, i32* %11
%16 = call i64 @vasprintf(i8** %12, i8* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %8
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %6
br label %31
22: ; preds = %5
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = load i8*, i8** %12
%27 = call i32 @vexpect_decode(i8* %23, i8* %24, i32 %25, i8* %26)
store i32 %27, i32* %13
%28 = load i8*, i8** %12
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %13
store i32 %30, i32* %6
br label %31
31: ; preds = %22, %18
%32 = load i32, i32* %6
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"error: vasprintf failed: %s\0A\00"
define i32 @vexpect(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%8 = call i64 @vasprintf(i8** %6, i8* %3, i32 %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %18
13: ; preds = %5
%14 = load i8*, i8** %6
%15 = call i32 @vexpect_decode(i8* %0, i8* %1, i32 %2, i8* %14)
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
br label %18
18: ; preds = %13, %10
%19 = phi i32 [ -1, %10 ], [ %15, %13 ]
ret i32 %19
}