#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, scalar_t__, int /*<<< orphan*/);
scalar_t__ memcmp(char *, int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
void read_header(uint32_t *width, uint32_t *height) {
  uint8_t hdr[16] = {0};
  if (fread(hdr, 1, strlen("farbfeld########"), stdin) !=
      strlen("farbfeld########")) {
    fprintf(stderr, "incomplete header\n");
    exit(1);
  }
  if (memcmp("farbfeld", hdr, strlen("farbfeld"))) {
    fprintf(stderr, "invalid magic value\n");
    exit(1);
  }
  *width = ntohl(*((uint32_t *)(hdr + 8)));
  *height = ntohl(*((uint32_t *)(hdr + 12)));
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xe61(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rdx
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x58(%rbp)
lea    0xe37(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
je     11fd <read_header+0x8d>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xe18(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
lea    0xe05(%rip),%rdi
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     124d <read_header+0xdd>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%edi
call   1090 <ntohl@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%edi
call   1090 <ntohl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdi
mov    $0x10,%edx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    $0x10,%rax
jne    11cc <read_header+0x7c>
lea    0xe78(%rip),%rdi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11de <read_header+0x8e>
mov    0x20(%rsp),%edi
call   1070 <ntohl@plt>
mov    %eax,(%rbx)
mov    0x30(%rsp),%edi
call   1070 <ntohl@plt>
mov    %eax,(%r14)
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
jmp    11ee <read_header+0x9e>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"farbfeld########\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"incomplete header\0A\00"
@.str.2 = [9 x i8] c"farbfeld\00"
@.str.3 = [21 x i8] c"invalid magic value\0A\00"
define void @read_header(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [16 x i32]
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = bitcast [16 x i32]* %5 to i8*
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%8 = call i64 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i64 @fread(i32* %7, i32 1, i64 %8, i32 %9)
%11 = call i64 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%19 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @memcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %18, i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%28 = getelementptr inbounds i32, i32* %27, i64 8
%29 = load i32, i32* %28
%30 = call i32 @ntohl(i32 %29)
%31 = load i32*, i32** %3
store i32 %30, i32* %31
%32 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%33 = getelementptr inbounds i32, i32* %32, i64 12
%34 = load i32, i32* %33
%35 = call i32 @ntohl(i32 %34)
%36 = load i32*, i32** %4
store i32 %35, i32* %36
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"incomplete header\0A\00"
@.str.2 = [9 x i8] c"farbfeld\00"
@.str.3 = [21 x i8] c"invalid magic value\0A\00"
define void @read_header(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca [16 x i32]
%4 = bitcast [16 x i32]* %3 to i8*
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i64 @fread(i32* %5, i32 1, i64 16, i32 %6)
%8 = icmp eq i64 %7, 16
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i64 @memcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %5, i64 8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 8
%22 = load i32, i32* %21
%23 = call i32 @ntohl(i32 %22)
store i32 %23, i32* %0
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 12
%25 = load i32, i32* %24
%26 = call i32 @ntohl(i32 %25)
store i32 %26, i32* %1
ret void
}