#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*/ stderr;
char *string_read(int /*<<< orphan*/ *);
int jtrace_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 {
      fprintf(stderr, "Header: %s\n", header);
      res = 0;
    }
    free(header);
  }
  return res;
}


x86 assembly (clang, -O0):
<jtrace_header_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <string_read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <jtrace_header_read+0x98>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x8,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11af <jtrace_header_read+0x6f>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x14(%rbp)
jmp    11cf <jtrace_header_read+0x8f>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@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):
<jtrace_header_read>:
push   %rbp
push   %rbx
push   %rax
call   1060 <string_read@plt>
test   %rax,%rax
je     119f <jtrace_header_read+0x5f>
mov    %rax,%rbx
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rax
lea    0xe86(%rip),%rsi
cmove  %rax,%rsi
lea    (%rcx,%rcx,1),%ebp
add    $0xfffffffe,%ebp
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11a4 <jtrace_header_read+0x64>
mov    $0xffffffff,%ebp
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 @jtrace_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 %24
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 %21
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 0, i32* %4
br label %21
21: ; preds = %17, %13
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %1
%25 = load i32, i32* %4
ret i32 %25
}

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 @jtrace_header_read(i32* %0) {
%2 = tail call i8* @string_read(i32* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, 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
%7 = load i32, i32* @stderr
%8 = select i1 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0)
%9 = select i1 %6, i32 0, i32 -2
%10 = tail call i32 @fprintf(i32 %7, i8* %8, i8* %2)
%11 = tail call i32 @free(i8* %2)
br label %12
12: ; preds = %4, %1
%13 = phi i32 [ %9, %4 ], [ -1, %1 ]
ret i32 %13
}