#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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int get_npix(char *buf) {
  int naxes;
  int npix;
  int naxis;
  char *where;
  char lookfor[80];
  int i;
  where = strstr(buf, "NAXIS");
  if (where == NULL) {
    fprintf(stderr, "cannot find NAXIS in header: aborting\n");
    return 0;
  }
  sscanf(where, "%*[^=] = %d", &naxes);
  if ((naxes < 1) || (naxes > 999)) {
    fprintf(stderr, "illegal value for %s: %d\n", lookfor, naxes);
    return 0;
  }
  npix = 1;
  for (i = 1; i <= naxes; i++) {
    sprintf(lookfor, "NAXIS%d", i);
    where = strstr(buf, lookfor);
    if (where == NULL) {
      fprintf(stderr, "cannot find %s in header: aborting\n", lookfor);
      return 0;
    }
    sscanf(where, "%*[^=] = %d", &naxis);
    if (naxis < 1) {
      fprintf(stderr, "error: found %s=%d\n", lookfor, naxis);
      return 0;
    }
    npix *= (int)naxis;
  }
  return npix;
}


x86 assembly (clang, -O0):
<get_npix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1191 <get_npix+0x51>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <get_npix+0x18b>
mov    -0x28(%rbp),%rdi
lea    0xe91(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmpl   $0x1,-0x14(%rbp)
jl     11bc <get_npix+0x7c>
cmpl   $0x3e7,-0x14(%rbp)
jle    11e6 <get_npix+0xa6>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <get_npix+0x18b>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12c5 <get_npix+0x185>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
lea    0xe3c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125f <get_npix+0x11f>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <get_npix+0x18b>
mov    -0x28(%rbp),%rdi
lea    0xdc3(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <sscanf@plt>
cmpl   $0x1,-0x1c(%rbp)
jge    12a7 <get_npix+0x167>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <get_npix+0x18b>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11f7 <get_npix+0xb7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_npix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
lea    0xea8(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11a3 <get_npix+0x63>
lea    0xec4(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
mov    0x8(%rsp),%ecx
lea    -0x3e8(%rcx),%eax
cmp    $0xfffffc19,%eax
jae    11c1 <get_npix+0x81>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
jmp    125c <get_npix+0x11c>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1263 <get_npix+0x123>
mov    $0x1,%ebx
xor    %ebp,%ebp
lea    0xe84(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1225 <get_npix+0xe5>
mov    %rax,%rdi
lea    0xe23(%rip),%rsi
mov    %r13,%rdx
call   1040 <sscanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    1245 <get_npix+0x105>
imul   %ecx,%ebx
cmp    0x8(%rsp),%ebp
jl     11e0 <get_npix+0xa0>
jmp    1263 <get_npix+0x123>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1263 <get_npix+0x123>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"NAXIS\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"cannot find NAXIS in header: aborting\0A\00"
@.str.2 = [12 x i8] c"%*[^=] = %d\00"
@.str.3 = [26 x i8] c"illegal value for %s: %d\0A\00"
@.str.4 = [8 x i8] c"NAXIS%d\00"
@.str.5 = [36 x i8] c"cannot find %s in header: aborting\0A\00"
@.str.6 = [20 x i8] c"error: found %s=%d\0A\00"
define i32 @get_npix(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [80 x i8]
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %67
17: ; preds = %1
%18 = load i8*, i8** %7
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 1
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 999
br i1 %24, label %25, label %30
25: ; preds = %22, %17
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %4
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %27, i32 %28)
store i32 0, i32* %2
br label %67
30: ; preds = %22
store i32 1, i32* %5
store i32 1, i32* %9
br label %31
31: ; preds = %62, %30
%32 = load i32, i32* %9
%33 = load i32, i32* %4
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %65
35: ; preds = %31
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* %9
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %3
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%41 = call i8* @strstr(i8* %39, i8* %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %46)
store i32 0, i32* %2
br label %67
48: ; preds = %35
%49 = load i8*, i8** %7
%50 = call i32 @sscanf(i8* %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%51 = load i32, i32* %6
%52 = icmp slt i32 %51, 1
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%56 = load i32, i32* %6
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %55, i32 %56)
store i32 0, i32* %2
br label %67
58: ; preds = %48
%59 = load i32, i32* %6
%60 = load i32, i32* %5
%61 = mul nsw i32 %60, %59
store i32 %61, i32* %5
br label %62
62: ; preds = %58
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %31
65: ; preds = %31
%66 = load i32, i32* %5
store i32 %66, i32* %2
br label %67
67: ; preds = %65, %53, %44, %25, %14
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@.str = [6 x i8] c"NAXIS\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"cannot find NAXIS in header: aborting\0A\00"
@.str.2 = [12 x i8] c"%*[^=] = %d\00"
@.str.3 = [26 x i8] c"illegal value for %s: %d\0A\00"
@.str.4 = [8 x i8] c"NAXIS%d\00"
@.str.5 = [36 x i8] c"cannot find %s in header: aborting\0A\00"
@.str.6 = [20 x i8] c"error: found %s=%d\0A\00"
define i32 @get_npix(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [80 x i8]
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %42
13: ; preds = %1
%14 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = add i32 %15, -1000
%17 = icmp ult i32 %16, -999
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %7, i32 %15)
br label %42
21: ; preds = %13, %37
%22 = phi i32 [ %39, %37 ], [ 1, %13 ]
%23 = phi i32 [ %38, %37 ], [ 1, %13 ]
%24 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%25 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %7)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %7)
br label %42
30: ; preds = %21
%31 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %7, i32 %32)
br label %42
37: ; preds = %30
%38 = mul nsw i32 %32, %23
%39 = add nuw nsw i32 %22, 1
%40 = load i32, i32* %2
%41 = icmp slt i32 %22, %40
br i1 %41, label %21, label %42
42: ; preds = %37, %34, %27, %18, %10
%43 = phi i32 [ 0, %10 ], [ 0, %18 ], [ 0, %27 ], [ 0, %34 ], [ %38, %37 ]
ret i32 %43
}