#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 wchar_t;

/* Variables and functions */
scalar_t__ WEOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ putwchar(int);
int /*<<< orphan*/ stderr;
void write_wchars(wchar_t buf[], size_t start, size_t end, bool escape,
                  bool open_field, bool close_field) {
  size_t j;
  if (escape) {
    if (open_field)
      putwchar(L'"');
    for (j = start; j <= end; ++j) {
      if (buf[(j % 4096)] == L'"')
        putwchar(L'"');
      if (putwchar(buf[(j % 4096)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
    if (close_field)
      putwchar(L'"');
  } else {
    for (j = start; j <= end; ++j) {
      if (putwchar(buf[(j % 4096)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
  }
}


x86 assembly (clang, -O0):
<write_wchars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     121b <write_wchars+0xeb>
cmpl   $0x0,-0x20(%rbp)
je     116d <write_wchars+0x3d>
mov    $0x22,%edi
call   1040 <putwchar@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     1202 <write_wchars+0xd2>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
and    $0xfff,%rcx
cmpl   $0x22,(%rax,%rcx,4)
jne    11a6 <write_wchars+0x76>
mov    $0x22,%edi
call   1040 <putwchar@plt>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
and    $0xfff,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <putwchar@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
jne    11ec <write_wchars+0xbc>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11f1 <write_wchars+0xc1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1175 <write_wchars+0x45>
cmpl   $0x0,-0x24(%rbp)
je     1216 <write_wchars+0xe6>
mov    $0x22,%edi
call   1040 <putwchar@plt>
jmp    1292 <write_wchars+0x162>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     128d <write_wchars+0x15d>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
and    $0xfff,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <putwchar@plt>
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%rax
jne    1277 <write_wchars+0x147>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    127c <write_wchars+0x14c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1223 <write_wchars+0xf3>
jmp    1292 <write_wchars+0x162>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_wchars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r15
test   %ecx,%ecx
je     11c0 <write_wchars+0x90>
mov    %r9d,%r12d
test   %r8d,%r8d
je     115a <write_wchars+0x2a>
mov    $0x22,%edi
call   1040 <putwchar@plt>
cmp    %r14,%rbp
ja     11a3 <write_wchars+0x73>
mov    0x2e72(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%ebx
and    $0xfff,%ebx
mov    (%r15,%rbx,4),%edi
cmp    $0x22,%edi
jne    118f <write_wchars+0x5f>
mov    $0x22,%edi
call   1040 <putwchar@plt>
mov    (%r15,%rbx,4),%edi
call   1040 <putwchar@plt>
cmp    0x0(%r13),%rax
je     11fd <write_wchars+0xcd>
add    $0x1,%rbp
cmp    %r14,%rbp
jbe    1170 <write_wchars+0x40>
test   %r12d,%r12d
je     11ee <write_wchars+0xbe>
mov    $0x22,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putwchar@plt>
cmp    %r14,%rbp
ja     11ee <write_wchars+0xbe>
mov    0x2e0c(%rip),%rbx
nopl   0x0(%rax)
mov    %ebp,%eax
and    $0xfff,%eax
mov    (%r15,%rax,4),%edi
call   1040 <putwchar@plt>
cmp    (%rbx),%rax
je     11fd <write_wchars+0xcd>
add    $0x1,%rbp
cmp    %r14,%rbp
jbe    11d0 <write_wchars+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@WEOF = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"putwchar error\00"
define void @write_wchars(i32* %0, i64 %1, i64 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store i32* %0, i32** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i32, i32* %10
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %59
16: ; preds = %6
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i64 @putwchar(i32 34)
br label %21
21: ; preds = %19, %16
%22 = load i64, i64* %8
store i64 %22, i64* %13
br label %23
23: ; preds = %50, %21
%24 = load i64, i64* %13
%25 = load i64, i64* %9
%26 = icmp ule i64 %24, %25
br i1 %26, label %27, label %53
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = load i64, i64* %13
%30 = urem i64 %29, 4096
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 34
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i64 @putwchar(i32 34)
br label %36
36: ; preds = %34, %27
%37 = load i32*, i32** %7
%38 = load i64, i64* %13
%39 = urem i64 %38, 4096
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i64 @putwchar(i32 %41)
%43 = load i64, i64* @WEOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %36
br label %50
50: ; preds = %49
%51 = load i64, i64* %13
%52 = add i64 %51, 1
store i64 %52, i64* %13
br label %23
53: ; preds = %23
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i64 @putwchar(i32 34)
br label %58
58: ; preds = %56, %53
br label %83
59: ; preds = %6
%60 = load i64, i64* %8
store i64 %60, i64* %13
br label %61
61: ; preds = %79, %59
%62 = load i64, i64* %13
%63 = load i64, i64* %9
%64 = icmp ule i64 %62, %63
br i1 %64, label %65, label %82
65: ; preds = %61
%66 = load i32*, i32** %7
%67 = load i64, i64* %13
%68 = urem i64 %67, 4096
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = load i32, i32* %69
%71 = call i64 @putwchar(i32 %70)
%72 = load i64, i64* @WEOF
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %78
74: ; preds = %65
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %65
br label %79
79: ; preds = %78
%80 = load i64, i64* %13
%81 = add i64 %80, 1
store i64 %81, i64* %13
br label %61
82: ; preds = %61
br label %83
83: ; preds = %82, %58
ret void
}

LLVM IR (-O2):
@WEOF = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"putwchar error\00"
define void @write_wchars(i32* nocapture %0, i64 %1, i64 %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = icmp ugt i64 %1, %2
br i1 %9, label %56, label %43
10: ; preds = %6
%11 = icmp eq i32 %4, 0
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i64 @putwchar(i32 34)
br label %14
14: ; preds = %12, %10
%15 = icmp ugt i64 %1, %2
br i1 %15, label %37, label %18
16: ; preds = %27
%17 = icmp ugt i64 %32, %2
br i1 %17, label %37, label %18
18: ; preds = %14, %16
%19 = phi i64 [ %32, %16 ], [ %1, %14 ]
%20 = and i64 %19, 4095
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = tail call i64 @putwchar(i32 34)
%26 = load i32, i32* %21
br label %27
27: ; preds = %24, %18
%28 = phi i32 [ %26, %24 ], [ %22, %18 ]
%29 = tail call i64 @putwchar(i32 %28)
%30 = load i64, i64* @WEOF
%31 = icmp eq i64 %29, %30
%32 = add i64 %19, 1
br i1 %31, label %33, label %16
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %16, %14
%38 = icmp eq i32 %5, 0
br i1 %38, label %56, label %39
39: ; preds = %37
%40 = tail call i64 @putwchar(i32 34)
br label %56
41: ; preds = %43
%42 = icmp ugt i64 %51, %2
br i1 %42, label %56, label %43
43: ; preds = %8, %41
%44 = phi i64 [ %51, %41 ], [ %1, %8 ]
%45 = and i64 %44, 4095
%46 = getelementptr inbounds i32, i32* %0, i64 %45
%47 = load i32, i32* %46
%48 = tail call i64 @putwchar(i32 %47)
%49 = load i64, i64* @WEOF
%50 = icmp eq i64 %48, %49
%51 = add i64 %44, 1
br i1 %50, label %52, label %41
52: ; preds = %43
%53 = load i32, i32* @stderr
%54 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %41, %8, %37, %39
ret void
}