#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void write_img(FILE *input, FILE *output, int white) {
  if (white == 0) {
    fputc(fgetc(input), output);
    fputc(fgetc(input), output);
    fputc(fgetc(input), output);
  } else {
    fgetc(input);
    fputc(255, output);
    fgetc(input);
    fputc(255, output);
    fgetc(input);
    fputc(255, output);
  }
}


x86 assembly (clang, -O0):
<write_img>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    117e <write_img+0x5e>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
jmp    11c3 <write_img+0xa3>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x10(%rbp),%rsi
mov    $0xff,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x10(%rbp),%rsi
mov    $0xff,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x10(%rbp),%rsi
mov    $0xff,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_img>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <fgetc@plt>
test   %ebp,%ebp
je     1166 <write_img+0x46>
mov    $0xff,%ebp
mov    $0xff,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    $0xff,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
jmp    118c <write_img+0x6c>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    %ebp,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fputc@plt>

LLVM IR (-O0):
define void @write_img(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = load i32*, i32** %4
%11 = call i32 @fgetc(i32* %10)
%12 = load i32*, i32** %5
%13 = call i32 @fputc(i32 %11, i32* %12)
%14 = load i32*, i32** %4
%15 = call i32 @fgetc(i32* %14)
%16 = load i32*, i32** %5
%17 = call i32 @fputc(i32 %15, i32* %16)
%18 = load i32*, i32** %4
%19 = call i32 @fgetc(i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @fputc(i32 %19, i32* %20)
br label %35
22: ; preds = %3
%23 = load i32*, i32** %4
%24 = call i32 @fgetc(i32* %23)
%25 = load i32*, i32** %5
%26 = call i32 @fputc(i32 255, i32* %25)
%27 = load i32*, i32** %4
%28 = call i32 @fgetc(i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fputc(i32 255, i32* %29)
%31 = load i32*, i32** %4
%32 = call i32 @fgetc(i32* %31)
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i32 255, i32* %33)
br label %35
35: ; preds = %22, %9
ret void
}

LLVM IR (-O2):
define void @write_img(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = tail call i32 @fgetc(i32* %0)
br i1 %4, label %6, label %11
6: ; preds = %3
%7 = tail call i32 @fputc(i32 %5, i32* %1)
%8 = tail call i32 @fgetc(i32* %0)
%9 = tail call i32 @fputc(i32 %8, i32* %1)
%10 = tail call i32 @fgetc(i32* %0)
br label %16
11: ; preds = %3
%12 = tail call i32 @fputc(i32 255, i32* %1)
%13 = tail call i32 @fgetc(i32* %0)
%14 = tail call i32 @fputc(i32 255, i32* %1)
%15 = tail call i32 @fgetc(i32* %0)
br label %16
16: ; preds = %11, %6
%17 = phi i32 [ 255, %11 ], [ %10, %6 ]
%18 = tail call i32 @fputc(i32 %17, i32* %1)
ret void
}