#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void put_image(char filename[100], char *in, int x_size, int y_size) {
  FILE *fd;
  if ((fd = fopen(filename, "w")) == NULL) {
    fprintf(stderr, "Can't output image%s.\n", filename);
    exit(0);
  };
  fprintf(fd, "P5\n");
  fprintf(fd, "%d %d\n", x_size, y_size);
  fprintf(fd, "255\n");
  if (fwrite(in, x_size * y_size, 1, fd) != 1) {
    fprintf(stderr, "Can't write image %s.\n", filename);
    exit(0);
  };
  fclose(fd);
}


x86 assembly (clang, -O0):
<put_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a6 <put_image+0x56>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     122c <put_image+0xdc>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_image>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d7 <put_image+0x87>
mov    %rax,%rbx
lea    0xe9b(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe8f(%rip),%rsi
mov    %ebx,%edi
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe81(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
imul   %r12d,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
jne    11e9 <put_image+0x99>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
jmp    11f9 <put_image+0xa9>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can't output image%s.\0A\00"
@.str.2 = [4 x i8] c"P5\0A\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
@.str.5 = [23 x i8] c"Can't write image %s.\0A\00"
define void @put_image(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%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 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %4
%19 = load i32*, i32** %9
%20 = ptrtoint i32* %19 to i32
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32*, i32** %9
%23 = ptrtoint i32* %22 to i32
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32*, i32** %9
%28 = ptrtoint i32* %27 to i32
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = mul nsw i32 %31, %32
%34 = load i32*, i32** %9
%35 = call i32 @fwrite(i8* %30, i32 %33, i32 1, i32* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %42
37: ; preds = %18
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %5
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %18
%43 = load i32*, i32** %9
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can't output image%s.\0A\00"
@.str.2 = [4 x i8] c"P5\0A\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
@.str.5 = [23 x i8] c"Can't write image %s.\0A\00"
define void @put_image(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, 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 %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %4
%12 = ptrtoint i32* %5 to i64
%13 = trunc i64 %12 to i32
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %3)
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = mul nsw i32 %3, %2
%18 = tail call i32 @fwrite(i8* %1, i32 %17, i32 1, i32* %5)
%19 = icmp eq i32 %18, 1
br i1 %19, label %24, label %20
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %11
%25 = tail call i32 @fclose(i32* %5)
ret void
}