#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int, int, int);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  FILE *dest;
  char magicNumber[3];
  int width, height, depth;
  unsigned char red, green, blue;
  unsigned char *buff;
  printf("Hello, World!\n");
  fp = fopen("lenna.ppm", "rb+");
  fscanf(fp, "%s", magicNumber);
  fscanf(fp, "%d %d %d", &width, &height, &depth);
  printf("%s %d %d %d nums\n", magicNumber, width, height, depth);
  dest = fopen("lena2.ppm", "wb+");
  fprintf(dest, "%s\n%d %d\n%d", magicNumber, width, height, depth);
  buff =
      (unsigned char *)malloc(sizeof(unsigned char) * ((width * height) * 3));
  fread(buff, 3 * (height), width, fp);
  for (int i = 0; i < width * height; ++i) {
    red = buff[i * 3 + 0];
    green = buff[i * 3 + 1];
    blue = buff[i * 3 + 2];
    fwrite(&red, 1, 1, dest);
    fwrite(&green, 1, 1, dest);
    fwrite(&blue, 1, 1, dest);
  }
  fclose(fp);
  printf("Hello, World!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1b(%rbp),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
mov    $0x0,%al
call   1060 <fscanf@plt>
lea    -0x1b(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1b(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xe14(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
imul   $0x3,%eax,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
imul   $0x3,-0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1030 <fread@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1308 <main+0x188>
mov    -0x38(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x38(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2a(%rbp)
mov    -0x38(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2b(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x18(%rbp),%rcx
lea    -0x2a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x18(%rbp),%rcx
lea    -0x2b(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1270 <main+0xf0>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4f(%rip),%rdi
lea    0xe52(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
lea    0xe47(%rip),%rsi
lea    0x15(%rsp),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
lea    0xe31(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x10(%rsp),%r8d
lea    0xe0d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0e(%rip),%rdi
lea    0xe11(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x10(%rsp),%r9d
lea    0xdf8(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    0xc(%rsp),%eax
imul   0x8(%rsp),%eax
lea    (%rax,%rax,2),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%eax
lea    (%rax,%rax,2),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1040 <fread@plt>
mov    0x8(%rsp),%eax
imul   0xc(%rsp),%eax
test   %eax,%eax
jle    12d6 <main+0x146>
add    $0x2,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edi
movsbl -0x1(%rbx),%r13d
movsbl (%rbx),%r12d
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    %r13d,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    %r12d,%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
movslq 0x8(%rsp),%rcx
imul   %rax,%rcx
add    $0x3,%rbx
cmp    %rcx,%rbp
jl     1290 <main+0x100>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd61(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Hello, World!\0A\00"
@.str.1 = [10 x i8] c"lenna.ppm\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%d %d %d\00"
@.str.5 = [18 x i8] c"%s %d %d %d nums\0A\00"
@.str.6 = [10 x i8] c"lena2.ppm\00"
@.str.7 = [4 x i8] c"wb+\00"
@.str.8 = [12 x i8] c"%s\0A%d %d\0A%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%17 = call i32 (i32*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %2
%19 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %20, i32 %21, i32 %22, i32 %23)
%25 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i32* %25, i32** %3
%26 = load i32*, i32** %3
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %27, i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = mul nsw i32 %32, %33
%35 = mul nsw i32 %34, 3
%36 = sext i32 %35 to i64
%37 = mul i64 1, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %11
%41 = load i8*, i8** %11
%42 = load i32, i32* %6
%43 = mul nsw i32 3, %42
%44 = load i32, i32* %5
%45 = load i32*, i32** %2
%46 = call i32 @fread(i8* %41, i32 %43, i32 %44, i32* %45)
store i32 0, i32* %12
br label %47
47: ; preds = %81, %0
%48 = load i32, i32* %12
%49 = load i32, i32* %5
%50 = load i32, i32* %6
%51 = mul nsw i32 %49, %50
%52 = icmp slt i32 %48, %51
br i1 %52, label %53, label %84
53: ; preds = %47
%54 = load i8*, i8** %11
%55 = load i32, i32* %12
%56 = mul nsw i32 %55, 3
%57 = add nsw i32 %56, 0
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
%60 = load i8, i8* %59
store i8 %60, i8* %8
%61 = load i8*, i8** %11
%62 = load i32, i32* %12
%63 = mul nsw i32 %62, 3
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
%67 = load i8, i8* %66
store i8 %67, i8* %9
%68 = load i8*, i8** %11
%69 = load i32, i32* %12
%70 = mul nsw i32 %69, 3
%71 = add nsw i32 %70, 2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %68, i64 %72
%74 = load i8, i8* %73
store i8 %74, i8* %10
%75 = load i32*, i32** %3
%76 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %75)
%77 = load i32*, i32** %3
%78 = call i32 @fwrite(i8* %9, i32 1, i32 1, i32* %77)
%79 = load i32*, i32** %3
%80 = call i32 @fwrite(i8* %10, i32 1, i32 1, i32* %79)
br label %81
81: ; preds = %53
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
br label %47
84: ; preds = %47
%85 = load i32*, i32** %2
%86 = call i32 @fclose(i32* %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"lenna.ppm\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%d %d %d\00"
@.str.5 = [18 x i8] c"%s %d %d %d nums\0A\00"
@.str.6 = [10 x i8] c"lena2.ppm\00"
@.str.7 = [4 x i8] c"wb+\00"
@.str.8 = [12 x i8] c"%s\0A%d %d\0A%d\00"
@str.9 = [14 x i8] c"Hello, World!\00"
define i32 @main() {
%1 = alloca [3 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i32*, i8*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%12 = call i32 (i32*, i8*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %5, i32 %13, i32 %14, i32 %15)
%17 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %5, i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = mul i32 %22, 3
%25 = mul i32 %24, %23
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* %3
%29 = mul nsw i32 %28, 3
%30 = load i32, i32* %2
%31 = call i32 @fread(i8* %27, i32 %29, i32 %30, i32* %10)
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = mul nsw i32 %33, %32
%35 = icmp sgt i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %39, %0
%37 = call i32 @fclose(i32* %10)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
ret i32 0
39: ; preds = %0, %39
%40 = phi i64 [ %56, %39 ], [ 0, %0 ]
%41 = mul nuw nsw i64 %40, 3
%42 = getelementptr inbounds i8, i8* %27, i64 %41
%43 = load i8, i8* %42
%44 = add nuw nsw i64 %41, 1
%45 = getelementptr inbounds i8, i8* %27, i64 %44
%46 = load i8, i8* %45
%47 = add nuw nsw i64 %41, 2
%48 = getelementptr inbounds i8, i8* %27, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %43 to i32
%51 = call i32 @fputc(i32 %50, i32* %17)
%52 = sext i8 %46 to i32
%53 = call i32 @fputc(i32 %52, i32* %17)
%54 = sext i8 %49 to i32
%55 = call i32 @fputc(i32 %54, i32* %17)
%56 = add nuw nsw i64 %40, 1
%57 = load i32, i32* %2
%58 = load i32, i32* %3
%59 = mul nsw i32 %58, %57
%60 = sext i32 %59 to i64
%61 = icmp slt i64 %56, %60
br i1 %61, label %39, label %36
}