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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *pgm_open_and_initialize(char *, int);
void pgm_from_image_raster(uint8_t *image_raster, uint8_t photo_index) {
  FILE *image = pgm_open_and_initialize("image", photo_index + 1);
  for (size_t i = 0; i < 16 * 14 * 8 * 8; i++) {
    fputc(image_raster[i] * 85, image);
  }
  fclose(image);
}


x86 assembly (clang, -O0):
<pgm_from_image_raster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xeb4(%rip),%rdi
call   1030 <pgm_open_and_initialize@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x3800,-0x20(%rbp)
jae    1191 <pgm_from_image_raster+0x61>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   $0x55,(%rax,%rcx,4),%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <pgm_from_image_raster+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgm_from_image_raster>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
add    $0x1,%esi
lea    0xebe(%rip),%rdi
call   1030 <pgm_open_and_initialize@plt>
mov    %rax,%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
imul   $0x55,(%r14,%rbx,4),%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbx
cmp    $0x3800,%rbx
jne    1150 <pgm_from_image_raster+0x20>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"image\00"
define void @pgm_from_image_raster(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = add nsw i32 %7, 1
%9 = call i32* @pgm_open_and_initialize(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32* %9, i32** %5
store i64 0, i64* %6
br label %10
10: ; preds = %21, %2
%11 = load i64, i64* %6
%12 = icmp ult i64 %11, 14336
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i64, i64* %6
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 85
%19 = load i32*, i32** %5
%20 = call i32 @fputc(i32 %18, i32* %19)
br label %21
21: ; preds = %13
%22 = load i64, i64* %6
%23 = add i64 %22, 1
store i64 %23, i64* %6
br label %10
24: ; preds = %10
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"image\00"
define void @pgm_from_image_raster(i32* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, 1
%4 = tail call i32* @pgm_open_and_initialize(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %7
5: ; preds = %7
%6 = tail call i32 @fclose(i32* %4)
ret void
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %13, %7 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, 85
%12 = tail call i32 @fputc(i32 %11, i32* %4)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, 14336
br i1 %14, label %5, label %7
}