#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *const);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *const);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void output_block_to_file(const char *progname, const char *filename,
                          const char *block, size_t count) {
  FILE *const out = fopen(filename, "w");
  if (!out) {
    fprintf(stderr, "%s: Could not open '%s': %s\n", progname, filename,
            strerror(errno));
    exit(1);
  }
  fputs("{\n    ", out);
  while (count--) {
    fprintf(out, "%d", *block);
    block++;
    if (count) {
      fputs(", ", out);
      if (!(count & 15)) {
        fputs("\n    ", out);
      }
    }
  }
  fputs("\n}\n", out);
  if (fclose(out)) {
    fprintf(stderr, "%s: Could not close '%s': %s\n", progname, filename,
            strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<output_block_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e7 <output_block_to_file+0x87>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     127e <output_block_to_file+0x11e>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1279 <output_block_to_file+0x119>
mov    -0x28(%rbp),%rsi
lea    0xddc(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1274 <output_block_to_file+0x114>
mov    -0x28(%rbp),%rsi
lea    0xdb1(%rip),%rdi
call   1040 <fputs@plt>
jmp    1279 <output_block_to_file+0x119>
jmp    11f7 <output_block_to_file+0x97>
mov    -0x28(%rbp),%rsi
lea    0xda3(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     12f1 <output_block_to_file+0x191>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %rax,%r8
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_block_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rsi,%rax
mov    %rdi,0x8(%rsp)
lea    0xe7d(%rip),%rsi
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1282 <output_block_to_file+0x122>
mov    %rax,%r12
lea    0xe7c(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
test   %rbx,%rbx
je     124d <output_block_to_file+0xed>
movsbl 0x0(%r13),%edx
lea    0xe5c(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffffffffffff,%rbx
je     124d <output_block_to_file+0xed>
add    $0x1,%r13
lea    0xe44(%rip),%rbp
lea    0xe34(%rip),%r14
lea    0xe33(%rip),%r15
jmp    121c <output_block_to_file+0xbc>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x0(%r13),%edx
mov    %r12d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r13
add    $0xffffffffffffffff,%rbx
je     124d <output_block_to_file+0xed>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r12,%rcx
call   1070 <fwrite@plt>
test   $0xf,%bl
jne    1200 <output_block_to_file+0xa0>
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %r12,%rcx
call   1070 <fwrite@plt>
jmp    1200 <output_block_to_file+0xa0>
lea    0xdd8(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    12a2 <output_block_to_file+0x142>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d57(%rip),%rax
mov    (%rax),%ebx
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd62(%rip),%rsi
jmp    12c0 <output_block_to_file+0x160>
mov    0x2d37(%rip),%rax
mov    (%rax),%ebx
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd70(%rip),%rsi
mov    %ebx,%edi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"%s: Could not open '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [7 x i8] c"{\0A \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [6 x i8] c"\0A \00"
@.str.6 = [4 x i8] c"\0A}\0A\00"
@.str.7 = [30 x i8] c"%s: Could not close '%s': %s\0A\00"
define void @output_block_to_file(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17, i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %4
%23 = load i32*, i32** %9
%24 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %50, %22
%26 = load i64, i64* %8
%27 = add i64 %26, -1
store i64 %27, i64* %8
%28 = icmp ne i64 %26, 0
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i32*, i32** %9
%31 = ptrtoint i32* %30 to i32
%32 = load i8*, i8** %7
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %7
%38 = load i64, i64* %8
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %29
%41 = load i32*, i32** %9
%42 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %41)
%43 = load i64, i64* %8
%44 = and i64 %43, 15
%45 = icmp ne i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i32*, i32** %9
%48 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %47)
br label %49
49: ; preds = %46, %40
br label %50
50: ; preds = %49, %29
br label %25
51: ; preds = %25
%52 = load i32*, i32** %9
%53 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %52)
%54 = load i32*, i32** %9
%55 = call i64 @fclose(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %51
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %5
%60 = load i8*, i8** %6
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %59, i8* %60, i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %51
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"%s: Could not open '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [7 x i8] c"{\0A \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [6 x i8] c"\0A \00"
@.str.6 = [4 x i8] c"\0A}\0A\00"
@.str.7 = [30 x i8] c"%s: Could not close '%s': %s\0A\00"
define void @output_block_to_file(i8* %0, i8* %1, i8* nocapture %2, i64 %3) {
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 6, i64 1, i32* %5)
%15 = icmp eq i64 %3, 0
br i1 %15, label %39, label %16
16: ; preds = %13
%17 = ptrtoint i32* %5 to i64
%18 = trunc i64 %17 to i32
%19 = add i64 %3, -1
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %19, 0
br i1 %23, label %39, label %24
24: ; preds = %16, %33
%25 = phi i8* [ %27, %33 ], [ %2, %16 ]
%26 = phi i64 [ %34, %33 ], [ %19, %16 ]
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %5)
%29 = and i64 %26, 15
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 5, i64 1, i32* %5)
br label %33
33: ; preds = %24, %31
%34 = add i64 %26, -1
%35 = load i8, i8* %27
%36 = sext i8 %35 to i32
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = icmp eq i64 %34, 0
br i1 %38, label %39, label %24
39: ; preds = %33, %16, %13
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %5)
%41 = tail call i64 @fclose(i32* %5)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %1, i8* %46)
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %39
ret void
}