#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 */
struct _IO_FILE {
  int dummy;
};

/* Variables and functions */
int _IO_getc(struct _IO_FILE *);
int /*<<< orphan*/ ppm_error(char *);
signed int ppm_readmagicnumber(struct _IO_FILE *file) {
  signed int ch1;
  signed int ch2;
  ch1 = _IO_getc(file);
  if (ch1 == -1)
    ppm_error((char *)"read error");
  ch2 = _IO_getc(file);
  if (ch2 == -1)
    ppm_error((char *)"read error");
  return ch1 * 256 + ch2;
}


x86 assembly (clang, -O0):
<ppm_readmagicnumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <_IO_getc@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    114e <ppm_readmagicnumber+0x2e>
lea    0xeb7(%rip),%rdi
call   1030 <ppm_error@plt>
mov    -0x8(%rbp),%rdi
call   1040 <_IO_getc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1170 <ppm_readmagicnumber+0x50>
lea    0xe95(%rip),%rdi
call   1030 <ppm_error@plt>
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
add    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppm_readmagicnumber>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <_IO_getc@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    113f <ppm_readmagicnumber+0x1f>
lea    0xec6(%rip),%rdi
call   1030 <ppm_error@plt>
mov    %r14,%rdi
call   1040 <_IO_getc@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    115a <ppm_readmagicnumber+0x3a>
lea    0xeab(%rip),%rdi
call   1030 <ppm_error@plt>
shl    $0x8,%ebx
add    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct._IO_FILE = type { i32 }
@.str = [11 x i8] c"read error\00"
define i32 @ppm_readmagicnumber(%struct._IO_FILE* %0) {
%2 = alloca %struct._IO_FILE*
%3 = alloca i32
%4 = alloca i32
store %struct._IO_FILE* %0, %struct._IO_FILE** %2
%5 = load %struct._IO_FILE*, %struct._IO_FILE** %2
%6 = call i32 @_IO_getc(%struct._IO_FILE* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @ppm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load %struct._IO_FILE*, %struct._IO_FILE** %2
%13 = call i32 @_IO_getc(%struct._IO_FILE* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @ppm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 256
%21 = load i32, i32* %4
%22 = add nsw i32 %20, %21
ret i32 %22
}

LLVM IR (-O2):
%struct._IO_FILE = type { i32 }
@.str = [11 x i8] c"read error\00"
define i32 @ppm_readmagicnumber(%struct._IO_FILE* nocapture %0) {
%2 = tail call i32 @_IO_getc(%struct._IO_FILE* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @ppm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @_IO_getc(%struct._IO_FILE* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @ppm_error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = shl nsw i32 %2, 8
%13 = add nsw i32 %7, %12
ret i32 %13
}