#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*/ errmsg(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int hdrgen(int npix, int nrast, int nframe, char *filename, char *title1,
           char *title2) {
  int indice[10], i;
  FILE *fp, *fpopen();
  for (i = 0; i < 10; i++)
    indice[i] = 0;
  if ((fp = fopen(filename, "w")) == NULL) {
    errmsg("Error: Unable to open header dataset");
    return (0);
  } else {
    fprintf(fp, "%s\n", title1);
    fprintf(fp, "%s\n", title2);
    indice[0] = npix;
    indice[1] = nrast;
    indice[2] = nframe;
    for (i = 0; i < 10; i++)
      fprintf(fp, "%8d", indice[i]);
    *(filename + 5) = '1';
    fprintf(fp, "\n%s\n", filename);
    fclose(fp);
    return (!0);
  }
}


x86 assembly (clang, -O0):
<hdrgen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0xa,-0x54(%rbp)
jge    1188 <hdrgen+0x48>
movslq -0x54(%rbp),%rax
movl   $0x0,-0x50(%rbp,%rax,4)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1164 <hdrgen+0x24>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    11be <hdrgen+0x7e>
lea    0xe55(%rip),%rdi
call   1050 <errmsg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1263 <hdrgen+0x123>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0xa,-0x54(%rbp)
jge    1235 <hdrgen+0xf5>
mov    -0x60(%rbp),%rdi
movslq -0x54(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1203 <hdrgen+0xc3>
mov    -0x18(%rbp),%rax
movb   $0x31,0x5(%rax)
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdrgen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r15
mov    %r8,%r13
mov    %rcx,%rbp
mov    %edx,%r14d
mov    %esi,0xc(%rsp)
mov    %edi,%r12d
lea    0xe98(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1274 <hdrgen+0x134>
mov    %rax,%rbx
mov    %rbp,0x10(%rsp)
mov    %r14d,%ebp
lea    0xea1(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe75(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x10(%rsp),%rdx
movb   $0x31,0x5(%rdx)
lea    0xdd0(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1282 <hdrgen+0x142>
lea    0xd87(%rip),%rdi
call   1050 <errmsg@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [37 x i8] c"Error: Unable to open header dataset\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [4 x i8] c"%8d\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
define i32 @hdrgen(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [10 x i32]
%15 = alloca i32
%16 = alloca i32*
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 0, i32* %15
br label %17
17: ; preds = %24, %6
%18 = load i32, i32* %15
%19 = icmp slt i32 %18, 10
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %15
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i64 0, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %15
%26 = add nsw i32 %25, 1
store i32 %26, i32* %15
br label %17
27: ; preds = %17
%28 = load i8*, i8** %11
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %16
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @errmsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %67
33: ; preds = %27
%34 = load i32*, i32** %16
%35 = load i8*, i8** %12
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %16
%38 = load i8*, i8** %13
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %8
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i64 0, i64 0
store i32 %40, i32* %41
%42 = load i32, i32* %9
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i64 0, i64 1
store i32 %42, i32* %43
%44 = load i32, i32* %10
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i64 0, i64 2
store i32 %44, i32* %45
store i32 0, i32* %15
br label %46
46: ; preds = %56, %33
%47 = load i32, i32* %15
%48 = icmp slt i32 %47, 10
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = load i32*, i32** %16
%51 = load i32, i32* %15
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %15
%58 = add nsw i32 %57, 1
store i32 %58, i32* %15
br label %46
59: ; preds = %46
%60 = load i8*, i8** %11
%61 = getelementptr inbounds i8, i8* %60, i64 5
store i8 49, i8* %61
%62 = load i32*, i32** %16
%63 = load i8*, i8** %11
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %63)
%65 = load i32*, i32** %16
%66 = call i32 @fclose(i32* %65)
store i32 1, i32* %7
br label %67
67: ; preds = %59, %31
%68 = load i32, i32* %7
ret i32 %68
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [37 x i8] c"Error: Unable to open header dataset\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [4 x i8] c"%8d\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
define i32 @hdrgen(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @errmsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %27
11: ; preds = %6
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%24 = getelementptr inbounds i8, i8* %3, i64 5
store i8 49, i8* %24
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%26 = tail call i32 @fclose(i32* %7)
br label %27
27: ; preds = %11, %9
%28 = phi i32 [ 0, %9 ], [ 1, %11 ]
ret i32 %28
}