#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_FAILURE;
size_t csv_write2(char *, size_t, char *, size_t, char);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fail_writer(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(size_t);
scalar_t__ memcmp(char *, char *, size_t);
int /*<<< orphan*/ stderr;
void test_writer2(char *test_name, char *input, size_t input_len,
                  char *expected, size_t expected_len, char quote) {
  size_t actual_len;
  char *temp = malloc(input_len * 2 + 2);
  if (!temp) {
    fprintf(stderr, "Failed to allocate memory in test_writer!\n");
    exit(EXIT_FAILURE);
  }
  actual_len = csv_write2(temp, input_len * 2 + 2, input, input_len, quote);
  if (actual_len != expected_len)
    fail_writer(test_name, "actual length doesn't match expected length");
  if (memcmp(temp, expected, actual_len) != 0)
    fail_writer(test_name, "actual data doesn't match expected data");
}


x86 assembly (clang, -O0):
<test_writer2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r9b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x1,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11c5 <test_writer2+0x65>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x1,%rsi
add    $0x2,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
movsbl -0x29(%rbp),%r8d
call   1030 <csv_write2@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1209 <test_writer2+0xa9>
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1070 <fail_writer@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     1234 <test_writer2+0xd4>
mov    -0x8(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <fail_writer@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_writer2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebp
mov    %r8,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
lea    (%rdx,%rdx,1),%r15
add    $0x2,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     120b <test_writer2+0xab>
mov    %rax,%rbx
movsbl %bpl,%r8d
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
call   1030 <csv_write2@plt>
mov    %rax,%rbp
cmp    0x8(%rsp),%rax
je     11ca <test_writer2+0x6a>
lea    0xe69(%rip),%rsi
mov    %r12,%rdi
call   1070 <fail_writer@plt>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11fc <test_writer2+0x9c>
lea    0xe71(%rip),%rsi
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fail_writer@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Failed to allocate memory in test_writer!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [44 x i8] c"actual length doesn't match expected length\00"
@.str.2 = [40 x i8] c"actual data doesn't match expected data\00"
define void @test_writer2(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4, i8 signext %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8
%13 = alloca i64
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
store i8 %5, i8* %12
%15 = load i64, i64* %9
%16 = mul i64 %15, 2
%17 = add i64 %16, 2
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %14
%19 = load i8*, i8** %14
%20 = icmp ne i8* %19, null
br i1 %20, label %26, label %21
21: ; preds = %6
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %6
%27 = load i8*, i8** %14
%28 = load i64, i64* %9
%29 = mul i64 %28, 2
%30 = add i64 %29, 2
%31 = load i8*, i8** %8
%32 = load i64, i64* %9
%33 = load i8, i8* %12
%34 = call i64 @csv_write2(i8* %27, i64 %30, i8* %31, i64 %32, i8 signext %33)
store i64 %34, i64* %13
%35 = load i64, i64* %13
%36 = load i64, i64* %11
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %26
%39 = load i8*, i8** %7
%40 = call i32 @fail_writer(i8* %39, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %38, %26
%42 = load i8*, i8** %14
%43 = load i8*, i8** %10
%44 = load i64, i64* %13
%45 = call i64 @memcmp(i8* %42, i8* %43, i64 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i8*, i8** %7
%49 = call i32 @fail_writer(i8* %48, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %47, %41
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Failed to allocate memory in test_writer!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [44 x i8] c"actual length doesn't match expected length\00"
@.str.2 = [40 x i8] c"actual data doesn't match expected data\00"
define void @test_writer2(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4, i8 signext %5) {
%7 = shl i64 %2, 1
%8 = add i64 %7, 2
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %6
%17 = tail call i64 @csv_write2(i8* %9, i64 %8, i8* %1, i64 %2, i8 signext %5)
%18 = icmp eq i64 %17, %4
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @fail_writer(i8* %0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = tail call i64 @memcmp(i8* %9, i8* %3, i64 %17)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @fail_writer(i8* %0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
ret void
}