#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 BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
int snprintf(char *, int, char *, ...);
int strlen(char *);
int image_ppm_write(const char *path, const int width, const int height,
                    const int Bpp, const unsigned char *buffer) {
  char buf[BUFSIZ];
  FILE *fp = NULL;
  int err = 0;
  if (width && height && Bpp && !buffer) {
    goto error;
  }
  fp = fopen(path, "w");
  if (NULL == fp) {
    goto error;
  }
  {
    __attribute__((unused)) const int i =
        snprintf(buf, BUFSIZ, "%s\n%i %i\n%i\n", "P3\n", width, height, 255);
    if (i >= BUFSIZ) {
      goto error;
    }
  }
  (void)0;
  {
    const size_t i = fwrite(buf, sizeof(char), strlen(buf), fp);
    if (i != strlen(buf) * sizeof(char)) {
      goto error;
    }
  }
  (void)0;
  if (Bpp) {
    const long pitch = width * Bpp;
    int x, y;
    for (y = 0; y < height; ++y) {
      const unsigned char *row = buffer + y * pitch;
      for (x = 0; x < width; ++x) {
        const unsigned char *pixel = row + x * Bpp;
        {
          __attribute__((unused)) const int i = snprintf(
              buf, BUFSIZ, "%u %u %u\n", pixel[0],
              Bpp > 1 ? pixel[1] : pixel[0], Bpp > 2 ? pixel[2] : pixel[0]);
          if (i >= BUFSIZ) {
            goto error;
          }
        }
        (void)0;
        {
          const size_t i = fwrite(buf, sizeof(char), strlen(buf), fp);
          if (i != strlen(buf) * sizeof(char)) {
            goto error;
          }
        }
        (void)0;
      }
      {
        const size_t i = fwrite("\n", sizeof(char), strlen("\n"), fp);
        if (i != strlen("\n") * sizeof(char)) {
          goto error;
        }
      }
      (void)0;
    }
  }
exit:
  if (fp)
    fclose(fp);
  return err;
error:
  goto exit;
}


x86 assembly (clang, -O0):
<image_ppm_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d8 <image_ppm_write+0x88>
cmpl   $0x0,-0x10(%rbp)
je     11d8 <image_ppm_write+0x88>
cmpl   $0x0,-0x14(%rbp)
je     11d8 <image_ppm_write+0x88>
cmpq   $0x0,-0x20(%rbp)
jne    11d8 <image_ppm_write+0x88>
jmp    14e5 <image_ppm_write+0x395>
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11fd <image_ppm_write+0xad>
jmp    14e5 <image_ppm_write+0x395>
mov    -0x88(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xde6(%rip),%rdx
lea    0xdec(%rip),%rcx
sub    $0x10,%rsp
movl   $0xff,(%rsp)
mov    $0x0,%al
call   1050 <snprintf@plt>
add    $0x10,%rsp
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%eax
jl     1253 <image_ppm_write+0x103>
jmp    14e5 <image_ppm_write+0x395>
mov    -0x88(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x90(%rbp)
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
cmp    %rcx,%rax
je     12af <image_ppm_write+0x15f>
jmp    14e5 <image_ppm_write+0x395>
cmpl   $0x0,-0x14(%rbp)
je     14bd <image_ppm_write+0x36d>
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    14b8 <image_ppm_write+0x368>
mov    -0x20(%rbp),%rax
movslq -0x58(%rbp),%rcx
imul   -0x50(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1449 <image_ppm_write+0x2f9>
mov    -0x60(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    -0x68(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x94(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    134e <image_ppm_write+0x1fe>
mov    -0x68(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x9c(%rbp)
jmp    135b <image_ppm_write+0x20b>
mov    -0x68(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    %eax,-0xa0(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    1384 <image_ppm_write+0x234>
mov    -0x68(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %eax,-0xa4(%rbp)
jmp    1391 <image_ppm_write+0x241>
mov    -0x68(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0xa0(%rbp),%r8d
mov    -0x94(%rbp),%ecx
mov    -0x98(%rbp),%esi
mov    -0x88(%rbp),%rdi
mov    -0xa4(%rbp),%r9d
lea    0xc5a(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2c13(%rip),%rcx
cmp    (%rcx),%eax
jl     13da <image_ppm_write+0x28a>
jmp    14e5 <image_ppm_write+0x395>
mov    -0x88(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xb0(%rbp)
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
cmp    %rcx,%rax
je     1436 <image_ppm_write+0x2e6>
jmp    14e5 <image_ppm_write+0x395>
jmp    143b <image_ppm_write+0x2eb>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12f4 <image_ppm_write+0x1a4>
lea    0xbc1(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
lea    0xbaf(%rip),%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    0xb8f(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xb8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
cmp    %rcx,%rax
je     14a5 <image_ppm_write+0x355>
jmp    14e5 <image_ppm_write+0x395>
jmp    14aa <image_ppm_write+0x35a>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12cd <image_ppm_write+0x17d>
jmp    14bd <image_ppm_write+0x36d>
jmp    14c2 <image_ppm_write+0x372>
cmpq   $0x0,-0x38(%rbp)
je     14d6 <image_ppm_write+0x386>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
jmp    14c2 <image_ppm_write+0x372>

x86 assembly (clang, -O2):
<image_ppm_write>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r15
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%ebx
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %esi,%esi
je     119d <image_ppm_write+0x4d>
test   %r14d,%r14d
je     119d <image_ppm_write+0x4d>
test   %r13d,%r13d
je     119d <image_ppm_write+0x4d>
test   %r15,%r15
je     1362 <image_ppm_write+0x212>
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
test   %rax,%rax
je     1362 <image_ppm_write+0x212>
mov    %r13d,-0x2c(%rbp)
mov    %r15,-0x48(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
sub    $0x8,%rsp
lea    0xe30(%rip),%rdx
lea    0xe36(%rip),%rcx
mov    %r12,%rdi
mov    %ebx,-0x30(%rbp)
mov    %ebx,%r8d
mov    %rax,%rbx
mov    %r14d,%r9d
xor    %eax,%eax
push   $0xff
call   1050 <snprintf@plt>
add    $0x10,%rsp
cmp    (%rbx),%eax
jge    1359 <image_ppm_write+0x209>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
call   1070 <fwrite@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1359 <image_ppm_write+0x209>
cltq
cmp    %rax,%rbx
jne    1359 <image_ppm_write+0x209>
test   %r14d,%r14d
jle    1359 <image_ppm_write+0x209>
mov    -0x2c(%rbp),%edx
mov    %edx,%eax
mov    -0x30(%rbp),%ecx
imul   %ecx,%eax
cltq
mov    %rax,-0x58(%rbp)
xor    %ebx,%ebx
cmp    $0x3,%edx
setge  %bl
add    %rbx,%rbx
movslq %edx,%rax
mov    %rax,-0x68(%rbp)
mov    %r14d,%eax
mov    %rax,-0x50(%rbp)
mov    %ecx,%eax
mov    %rax,-0x60(%rbp)
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
mov    -0x60(%rbp),%r15
mov    -0x48(%rbp),%r13
cmpl   $0x0,-0x30(%rbp)
jle    1304 <image_ppm_write+0x1b4>
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13),%ecx
mov    %ecx,%r8d
cmpl   $0x2,-0x2c(%rbp)
jl     12a3 <image_ppm_write+0x153>
movzbl 0x1(%r13),%r8d
mov    0x2d36(%rip),%r14
mov    (%r14),%esi
movzbl 0x0(%r13,%rbx,1),%r9d
mov    %r12,%rdi
lea    0xd56(%rip),%rdx
xor    %eax,%eax
call   1050 <snprintf@plt>
cmp    (%r14),%eax
jge    1359 <image_ppm_write+0x209>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
call   1070 <fwrite@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r14
jne    1359 <image_ppm_write+0x209>
add    -0x68(%rbp),%r13
add    $0xffffffffffffffff,%r15
jne    1290 <image_ppm_write+0x140>
lea    0xd06(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
call   1070 <fwrite@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r14
jne    1359 <image_ppm_write+0x209>
mov    -0x40(%rbp),%rcx
add    $0x1,%rcx
mov    -0x58(%rbp),%rax
add    %rax,-0x48(%rbp)
mov    %rcx,%rax
mov    %rcx,-0x40(%rbp)
cmp    -0x50(%rbp),%rcx
jne    127a <image_ppm_write+0x12a>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [13 x i8] c"%s\0A%i %i\0A%i\0A\00"
@.str.2 = [4 x i8] c"P3\0A\00"
@.str.3 = [10 x i8] c"%u %u %u\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @image_ppm_write(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %11
%28 = alloca i8, i64 %26
store i64 %26, i64* %12
store i32* null, i32** %13
store i32 0, i32* %14
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %5
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* %9
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %37
br label %173
41: ; preds = %37, %34, %31, %5
%42 = load i8*, i8** %6
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %43, i32** %13
%44 = load i32*, i32** %13
%45 = icmp eq i32* null, %44
br i1 %45, label %46, label %47
46: ; preds = %41
br label %173
47: ; preds = %41
%48 = load i32, i32* @BUFSIZ
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %50, i32 255)
store i32 %51, i32* %15
%52 = load i32, i32* %15
%53 = load i32, i32* @BUFSIZ
%54 = icmp sge i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %47
br label %173
56: ; preds = %47
%57 = call i32 @strlen(i8* %28)
%58 = load i32*, i32** %13
%59 = call i64 @fwrite(i8* %28, i32 1, i32 %57, i32* %58)
store i64 %59, i64* %16
%60 = load i64, i64* %16
%61 = call i32 @strlen(i8* %28)
%62 = sext i32 %61 to i64
%63 = mul i64 %62, 1
%64 = icmp ne i64 %60, %63
br i1 %64, label %65, label %66
65: ; preds = %56
br label %173
66: ; preds = %56
%67 = load i32, i32* %9
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %163
69: ; preds = %66
%70 = load i32, i32* %7
%71 = load i32, i32* %9
%72 = mul nsw i32 %70, %71
%73 = sext i32 %72 to i64
store i64 %73, i64* %17
store i32 0, i32* %19
br label %74
74: ; preds = %159, %69
%75 = load i32, i32* %19
%76 = load i32, i32* %8
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %162
78: ; preds = %74
%79 = load i8*, i8** %10
%80 = load i32, i32* %19
%81 = sext i32 %80 to i64
%82 = load i64, i64* %17
%83 = mul nsw i64 %81, %82
%84 = getelementptr inbounds i8, i8* %79, i64 %83
store i8* %84, i8** %20
store i32 0, i32* %18
br label %85
85: ; preds = %145, %78
%86 = load i32, i32* %18
%87 = load i32, i32* %7
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %148
89: ; preds = %85
%90 = load i8*, i8** %20
%91 = load i32, i32* %18
%92 = load i32, i32* %9
%93 = mul nsw i32 %91, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %90, i64 %94
store i8* %95, i8** %21
%96 = load i32, i32* @BUFSIZ
%97 = load i8*, i8** %21
%98 = getelementptr inbounds i8, i8* %97, i64 0
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = load i32, i32* %9
%102 = icmp sgt i32 %101, 1
br i1 %102, label %103, label %108
103: ; preds = %89
%104 = load i8*, i8** %21
%105 = getelementptr inbounds i8, i8* %104, i64 1
%106 = load i8, i8* %105
%107 = zext i8 %106 to i32
br label %113
108: ; preds = %89
%109 = load i8*, i8** %21
%110 = getelementptr inbounds i8, i8* %109, i64 0
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
br label %113
113: ; preds = %108, %103
%114 = phi i32 [ %107, %103 ], [ %112, %108 ]
%115 = load i32, i32* %9
%116 = icmp sgt i32 %115, 2
br i1 %116, label %117, label %122
117: ; preds = %113
%118 = load i8*, i8** %21
%119 = getelementptr inbounds i8, i8* %118, i64 2
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
br label %127
122: ; preds = %113
%123 = load i8*, i8** %21
%124 = getelementptr inbounds i8, i8* %123, i64 0
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
br label %127
127: ; preds = %122, %117
%128 = phi i32 [ %121, %117 ], [ %126, %122 ]
%129 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 %96, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %100, i32 %114, i32 %128)
store i32 %129, i32* %22
%130 = load i32, i32* %22
%131 = load i32, i32* @BUFSIZ
%132 = icmp sge i32 %130, %131
br i1 %132, label %133, label %134
133: ; preds = %127
br label %173
134: ; preds = %127
%135 = call i32 @strlen(i8* %28)
%136 = load i32*, i32** %13
%137 = call i64 @fwrite(i8* %28, i32 1, i32 %135, i32* %136)
store i64 %137, i64* %23
%138 = load i64, i64* %23
%139 = call i32 @strlen(i8* %28)
%140 = sext i32 %139 to i64
%141 = mul i64 %140, 1
%142 = icmp ne i64 %138, %141
br i1 %142, label %143, label %144
143: ; preds = %134
br label %173
144: ; preds = %134
br label %145
145: ; preds = %144
%146 = load i32, i32* %18
%147 = add nsw i32 %146, 1
store i32 %147, i32* %18
br label %85
148: ; preds = %85
%149 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%150 = load i32*, i32** %13
%151 = call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %149, i32* %150)
store i64 %151, i64* %24
%152 = load i64, i64* %24
%153 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%154 = sext i32 %153 to i64
%155 = mul i64 %154, 1
%156 = icmp ne i64 %152, %155
br i1 %156, label %157, label %158
157: ; preds = %148
br label %173
158: ; preds = %148
br label %159
159: ; preds = %158
%160 = load i32, i32* %19
%161 = add nsw i32 %160, 1
store i32 %161, i32* %19
br label %74
162: ; preds = %74
br label %163
163: ; preds = %162, %66
br label %164
164: ; preds = %173, %163
%165 = load i32*, i32** %13
%166 = icmp ne i32* %165, null
br i1 %166, label %167, label %170
167: ; preds = %164
%168 = load i32*, i32** %13
%169 = call i32 @fclose(i32* %168)
br label %170
170: ; preds = %167, %164
%171 = load i32, i32* %14
%172 = load i8*, i8** %11
ret i32 %171
173: ; preds = %157, %143, %133, %65, %55, %46, %40
br label %164
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [13 x i8] c"%s\0A%i %i\0A%i\0A\00"
@.str.2 = [4 x i8] c"P3\0A\00"
@.str.3 = [10 x i8] c"%u %u %u\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @image_ppm_write(i8* nocapture %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp ne i32 %1, 0
%10 = icmp ne i32 %2, 0
%11 = and i1 %9, %10
%12 = icmp ne i32 %3, 0
%13 = and i1 %11, %12
%14 = icmp eq i8* %4, null
%15 = and i1 %13, %14
br i1 %15, label %86, label %16
16: ; preds = %5
%17 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %86, label %19
19: ; preds = %16
%20 = load i32, i32* @BUFSIZ
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %2, i32 255)
%22 = load i32, i32* @BUFSIZ
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %84
24: ; preds = %19
%25 = call i32 @strlen(i8* %8)
%26 = call i64 @fwrite(i8* %8, i32 1, i32 %25, i32* %17)
%27 = call i32 @strlen(i8* %8)
%28 = sext i32 %27 to i64
%29 = icmp eq i64 %26, %28
%30 = and i1 %12, %29
br i1 %30, label %31, label %84
31: ; preds = %24
%32 = mul nsw i32 %3, %1
%33 = sext i32 %32 to i64
%34 = icmp sgt i32 %2, 0
br i1 %34, label %35, label %84
35: ; preds = %31
%36 = icmp sgt i32 %1, 0
%37 = icmp sgt i32 %3, 1
%38 = icmp sgt i32 %3, 2
%39 = select i1 %38, i64 2, i64 0
%40 = sext i32 %3 to i64
%41 = zext i32 %2 to i64
%42 = zext i32 %1 to i64
br label %43
43: ; preds = %75, %35
%44 = phi i64 [ 0, %35 ], [ %81, %75 ]
%45 = mul nsw i64 %44, %33
%46 = getelementptr inbounds i8, i8* %4, i64 %45
br i1 %36, label %49, label %75
47: ; preds = %68
%48 = icmp eq i64 %74, %42
br i1 %48, label %75, label %49
49: ; preds = %43, %47
%50 = phi i64 [ %74, %47 ], [ 0, %43 ]
%51 = mul nsw i64 %50, %40
%52 = getelementptr inbounds i8, i8* %46, i64 %51
%53 = load i32, i32* @BUFSIZ
%54 = load i8, i8* %52
%55 = zext i8 %54 to i32
br i1 %37, label %56, label %60
56: ; preds = %49
%57 = getelementptr inbounds i8, i8* %52, i64 1
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
br label %60
60: ; preds = %49, %56
%61 = phi i32 [ %59, %56 ], [ %55, %49 ]
%62 = getelementptr i8, i8* %52, i64 %39
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %55, i32 %61, i32 %64)
%66 = load i32, i32* @BUFSIZ
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %84
68: ; preds = %60
%69 = call i32 @strlen(i8* %8)
%70 = call i64 @fwrite(i8* %8, i32 1, i32 %69, i32* %17)
%71 = call i32 @strlen(i8* %8)
%72 = sext i32 %71 to i64
%73 = icmp eq i64 %70, %72
%74 = add nuw nsw i64 %50, 1
br i1 %73, label %47, label %84
75: ; preds = %47, %43
%76 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%77 = call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %76, i32* %17)
%78 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%79 = sext i32 %78 to i64
%80 = icmp ne i64 %77, %79
%81 = add nuw nsw i64 %44, 1
%82 = icmp eq i64 %81, %41
%83 = select i1 %80, i1 true, i1 %82
br i1 %83, label %84, label %43
84: ; preds = %75, %68, %60, %31, %24, %19
%85 = call i32 @fclose(i32* %17)
br label %86
86: ; preds = %5, %16, %84
ret i32 0
}