#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*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void write_footer(FILE *out, int n_images, const char *struct_name) {
  int i;
  if (n_images > 1) {
    fprintf(out, "static struct image *%s[] = {\n", struct_name);
    for (i = 0; i < n_images; i++)
      fprintf(out, "    &%s%d,\n", struct_name, i);
    fputs("};\n\n", out);
  }
  fputs("#endif", out);
}


x86 assembly (clang, -O0):
<write_footer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    119d <write_footer+0x7d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118d <write_footer+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <write_footer+0x3a>
mov    -0x8(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1030 <fputs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_footer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
cmp    $0x2,%esi
jl     1182 <write_footer+0x62>
mov    %rdx,%r12
mov    %esi,%ebp
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xed2(%rip),%r15
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1150 <write_footer+0x30>
lea    0xebb(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
lea    0xea7(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"static struct image *%s[] = {\0A\00"
@.str.1 = [12 x i8] c" &%s%d,\0A\00"
@.str.2 = [5 x i8] c"};\0A\0A\00"
@.str.3 = [7 x i8] c"#endif\00"
define void @write_footer(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %29
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = load i8*, i8** %6
%13 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %7
br label %14
14: ; preds = %23, %10
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
br label %23
23: ; preds = %18
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %14
26: ; preds = %14
%27 = load i32*, i32** %4
%28 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %26, %3
%30 = load i32*, i32** %4
%31 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"static struct image *%s[] = {\0A\00"
@.str.1 = [12 x i8] c" &%s%d,\0A\00"
@.str.2 = [5 x i8] c"};\0A\0A\00"
@.str.3 = [7 x i8] c"#endif\00"
define void @write_footer(i32* nocapture %0, i32 %1, i8* %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %14
5: ; preds = %3
%6 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ %10, %7 ], [ 0, %5 ]
%9 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %8)
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %14
14: ; preds = %12, %3
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 6, i64 1, i32* %0)
ret void
}