#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 */

/* Variables and functions */
int unpack_int16(char const *, int);
void opesci_segy_get_format(const char *header, int *format_code,
                            int *swap_endian) {
  int j;
  *swap_endian = 0;
  for (j = 0; j < 2; j++) {
    *format_code = unpack_int16(header + 3224, *swap_endian);
    if (*format_code < 1 || *format_code > 8) {
      *swap_endian = 1;
      continue;
    }
  }
}


x86 assembly (clang, -O0):
<opesci_segy_get_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1199 <opesci_segy_get_format+0x89>
mov    -0x8(%rbp),%rdi
add    $0xc98,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <unpack_int16@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jl     1177 <opesci_segy_get_format+0x67>
mov    -0x10(%rbp),%rax
cmpl   $0x8,(%rax)
jle    1186 <opesci_segy_get_format+0x76>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    118b <opesci_segy_get_format+0x7b>
jmp    118b <opesci_segy_get_format+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <opesci_segy_get_format+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opesci_segy_get_format>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rdx)
add    $0xc98,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <unpack_int16@plt>
mov    %eax,(%r14)
add    $0xfffffff7,%eax
cmp    $0xfffffff8,%eax
jae    114e <opesci_segy_get_format+0x3e>
movl   $0x1,(%r15)
mov    $0x1,%esi
jmp    1151 <opesci_segy_get_format+0x41>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <unpack_int16@plt>
mov    %eax,(%r14)
add    $0xfffffff7,%eax
cmp    $0xfffffff7,%eax
ja     116b <opesci_segy_get_format+0x5b>
movl   $0x1,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @opesci_segy_get_format(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %29, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 3224
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = call i32 @unpack_int16(i8* %14, i32 %16)
%18 = load i32*, i32** %5
store i32 %17, i32* %18
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = icmp slt i32 %20, 1
br i1 %21, label %26, label %22
22: ; preds = %12
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = icmp sgt i32 %24, 8
br i1 %25, label %26, label %28
26: ; preds = %22, %12
%27 = load i32*, i32** %6
store i32 1, i32* %27
br label %29
28: ; preds = %22
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %9
32: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @opesci_segy_get_format(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2) {
store i32 0, i32* %2
%4 = getelementptr inbounds i8, i8* %0, i64 3224
%5 = tail call i32 @unpack_int16(i8* %4, i32 0)
store i32 %5, i32* %1
%6 = add i32 %5, -9
%7 = icmp ult i32 %6, -8
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = load i32, i32* %2
br label %11
10: ; preds = %3
store i32 1, i32* %2
br label %11
11: ; preds = %8, %10
%12 = phi i32 [ %9, %8 ], [ 1, %10 ]
%13 = tail call i32 @unpack_int16(i8* %4, i32 %12)
store i32 %13, i32* %1
%14 = add i32 %13, -9
%15 = icmp ult i32 %14, -8
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %2
br label %17
17: ; preds = %16, %11
ret void
}