#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int get_bitpix(char *buf) {
  int bitpix;
  char *where;
  where = strstr(buf, "BITPIX");
  if (where == NULL) {
    fprintf(stderr, "cannot find BITPIX in header: aborting\n");
    return 0;
  }
  sscanf(where, "%*[^=] = %d", &bitpix);
  if ((bitpix != 8) && (bitpix != 16) && (bitpix != 32) && (bitpix != -32) &&
      (bitpix != -64)) {
    bitpix = 0;
  }
  return bitpix;
}


x86 assembly (clang, -O0):
<get_bitpix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <get_bitpix+0x4c>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cf <get_bitpix+0x9f>
mov    -0x20(%rbp),%rdi
lea    0xea8(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmpl   $0x8,-0x14(%rbp)
je     11c9 <get_bitpix+0x99>
cmpl   $0x10,-0x14(%rbp)
je     11c9 <get_bitpix+0x99>
cmpl   $0x20,-0x14(%rbp)
je     11c9 <get_bitpix+0x99>
cmpl   $0xffffffe0,-0x14(%rbp)
je     11c9 <get_bitpix+0x99>
cmpl   $0xffffffc0,-0x14(%rbp)
je     11c9 <get_bitpix+0x99>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bitpix>:
push   %rax
lea    0xec8(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1172 <get_bitpix+0x42>
lea    0xee6(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x20,%rax
ja     1189 <get_bitpix+0x59>
movabs $0x100010100,%rcx
bt     %rax,%rcx
jae    1189 <get_bitpix+0x59>
pop    %rcx
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1193 <get_bitpix+0x63>
cmp    $0xffffffc0,%eax
je     1170 <get_bitpix+0x40>
cmp    $0xffffffe0,%eax
je     1170 <get_bitpix+0x40>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"BITPIX\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"cannot find BITPIX in header: aborting\0A\00"
@.str.2 = [12 x i8] c"%*[^=] = %d\00"
define i32 @get_bitpix(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %33
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 8
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 16
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 32
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, -32
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, -64
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %4
br label %31
31: ; preds = %30, %27, %24, %21, %18, %13
%32 = load i32, i32* %4
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %10
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [7 x i8] c"BITPIX\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"cannot find BITPIX in header: aborting\0A\00"
@.str.2 = [12 x i8] c"%*[^=] = %d\00"
define i32 @get_bitpix(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %13
9: ; preds = %1
%10 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %12 [
i32 -32, label %13
i32 -64, label %13
i32 32, label %13
i32 16, label %13
i32 8, label %13
]
12: ; preds = %9
br label %13
13: ; preds = %12, %9, %9, %9, %9, %9, %6
%14 = phi i32 [ 0, %6 ], [ %11, %9 ], [ %11, %9 ], [ %11, %9 ], [ %11, %9 ], [ %11, %9 ], [ 0, %12 ]
ret i32 %14
}