#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*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ stderr;
int GetSegmentLength(int segment, int segmentCheck, FILE *f) {
  segment = fgetc(f);
  if (segment != segmentCheck) {
    fprintf(stderr, "Error in header segment: %d, should be %d\n", segment,
            segmentCheck);
    exit(1);
  }
  return ((fgetc(f) << 8) + fgetc(f));
}


x86 assembly (clang, -O0):
<GetSegmentLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     117f <GetSegmentLength+0x4f>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetSegmentLength>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdx,%rdi
call   1030 <fgetc@plt>
cmp    %ebp,%eax
jne    1162 <GetSegmentLength+0x32>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e77(%rip),%rcx
mov    (%rcx),%edi
lea    0xe8e(%rip),%rsi
mov    %eax,%edx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Error in header segment: %d, should be %d\0A\00"
define i32 @GetSegmentLength(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32*, i32** %6
%20 = call i32 @fgetc(i32* %19)
%21 = shl i32 %20, 8
%22 = load i32*, i32** %6
%23 = call i32 @fgetc(i32* %22)
%24 = add nsw i32 %21, %23
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Error in header segment: %d, should be %d\0A\00"
define i32 @GetSegmentLength(i32 %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 @fgetc(i32* %2)
%5 = icmp eq i32 %4, %1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %1)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 @fgetc(i32* %2)
%12 = shl i32 %11, 8
%13 = tail call i32 @fgetc(i32* %2)
%14 = add nsw i32 %12, %13
ret i32 %14
}