#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *string_read(int /*<<< orphan*/ *);
int header_read(FILE *f) {
  char *header;
  int res = -1;
  header = string_read(f);
  if (header) {
    if (memcmp(header, "version ", 8)) {
      fprintf(stderr, "Wrong header: %s\n", header);
      res = -2;
    } else {
      printf("Header: %s\n", header);
      res = 0;
    }
    free(header);
  }
  return res;
}


x86 assembly (clang, -O0):
<header_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <string_read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11df <header_read+0x8f>
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11bf <header_read+0x6f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xfffffffe,-0x14(%rbp)
jmp    11d6 <header_read+0x86>
mov    -0x10(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_read>:
push   %rbp
push   %rbx
push   %rax
call   1070 <string_read@plt>
test   %rax,%rax
je     1198 <header_read+0x48>
mov    %rax,%rbx
lea    0xe99(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     119f <header_read+0x4f>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    $0xfffffffe,%ebp
jmp    11b0 <header_read+0x60>
mov    $0xffffffff,%ebp
jmp    11b8 <header_read+0x68>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"version \00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Wrong header: %s\0A\00"
@.str.2 = [12 x i8] c"Header: %s\0A\00"
define i32 @header_read(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
store i32* %0, i32** %2
store i32 -1, i32* %4
%5 = load i32*, i32** %2
%6 = call i8* @string_read(i32* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %23
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @memcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -2, i32* %4
br label %20
17: ; preds = %9
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %18)
store i32 0, i32* %4
br label %20
20: ; preds = %17, %13
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %20, %1
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [9 x i8] c"version \00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Wrong header: %s\0A\00"
@.str.2 = [12 x i8] c"Header: %s\0A\00"
define i32 @header_read(i32* %0) {
%2 = tail call i8* @string_read(i32* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i64 @memcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %12
10: ; preds = %4
%11 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ -2, %7 ], [ 0, %10 ]
%14 = tail call i32 @free(i8* %2)
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ %13, %12 ], [ -1, %1 ]
ret i32 %16
}