#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int Init_PIC_files(char *basename, FILE **fd, int nb, int nr, int yb) {
  char fname[80], ext[8];
  int i, n, yb_tot;
  yb_tot = 1 + (nr - 1) / 400;
  for (i = 0; nb > 0; i++, nb -= (640 >> 3)) {
    if (fd[i]) {
      fclose(fd[i]);
      fd[i] = NULL;
    }
    n = yb + i * yb_tot;
    if (n > 99) {
      fprintf(stderr, "ERROR: Too many PIC files per column!\n");
      for (; i > -1; i--)
        if (fd[i]) {
          fclose(fd[i]);
          fd[i] = NULL;
        }
      return (-1);
    }
    sprintf(ext, "%02d.pic", n);
    strcpy(fname, basename);
    strncat(fname, ext, 80 - strlen(basename) - 1);
    if ((fd[i] = fopen(fname, "w+")) == NULL) {
      perror("hp2xx -- opening PIC file(s)");
      return (-1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<Init_PIC_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x8c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1376 <Init_PIC_files+0x1f6>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1205 <Init_PIC_files+0x85>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
mov    -0x8c(%rbp),%ecx
imul   -0x94(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x90(%rbp)
cmpl   $0x63,-0x90(%rbp)
jle    12ae <Init_PIC_files+0x12e>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
call   1070 <fprintf@plt>
cmpl   $0xffffffff,-0x8c(%rbp)
jle    12a2 <Init_PIC_files+0x122>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1289 <Init_PIC_files+0x109>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    128e <Init_PIC_files+0x10e>
mov    -0x8c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8c(%rbp)
jmp    123f <Init_PIC_files+0xbf>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <Init_PIC_files+0x1fd>
lea    -0x88(%rbp),%rdi
mov    -0x90(%rbp),%edx
lea    0xd65(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x88(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    $0x50,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1060 <strncat@plt>
lea    -0x80(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   1080 <fopen@plt>
mov    -0x18(%rbp),%rcx
movslq -0x8c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1354 <Init_PIC_files+0x1d4>
lea    0xcf0(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <Init_PIC_files+0x1fd>
jmp    1359 <Init_PIC_files+0x1d9>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x50,%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <Init_PIC_files+0x3e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Init_PIC_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x10(%rsp)
xor    %eax,%eax
test   %edx,%edx
jle    12b1 <Init_PIC_files+0x131>
mov    %r8d,%ebp
mov    %edx,%ebx
mov    %rsi,%r15
add    $0xffffffff,%ecx
movslq %ecx,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
sar    $0x27,%rcx
shr    $0x3f,%rax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
add    $0x50,%ebx
mov    $0x1,%r14d
nop
mov    -0x8(%r15,%r14,8),%rdi
test   %rdi,%rdi
je     11e8 <Init_PIC_files+0x68>
call   1040 <fclose@plt>
movq   $0x0,-0x8(%r15,%r14,8)
cmp    $0x64,%ebp
jge    1268 <Init_PIC_files+0xe8>
lea    0x18(%rsp),%rdi
lea    0xe2e(%rip),%rsi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%r13
mov    0x10(%rsp),%r15
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r13,%r15
call   1050 <strlen@plt>
mov    $0x4f,%edx
sub    %eax,%edx
mov    %r12,%rdi
lea    0x18(%rsp),%rsi
call   1060 <strncat@plt>
mov    %r12,%rdi
lea    0xdef(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%r13,%r14,8)
test   %rax,%rax
je     12a0 <Init_PIC_files+0x120>
add    $0x1,%r14
add    0xc(%rsp),%ebp
add    $0xffffffb0,%ebx
cmp    $0x50,%ebx
jg     11d0 <Init_PIC_files+0x50>
xor    %eax,%eax
jmp    12b1 <Init_PIC_files+0x131>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1286 <Init_PIC_files+0x106>
nop
add    $0xffffffffffffffff,%r14
jle    12ac <Init_PIC_files+0x12c>
mov    -0x8(%r15,%r14,8),%rdi
test   %rdi,%rdi
je     1280 <Init_PIC_files+0x100>
call   1040 <fclose@plt>
movq   $0x0,-0x8(%r15,%r14,8)
jmp    1280 <Init_PIC_files+0x100>
lea    0xd8c(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"ERROR: Too many PIC files per column!\0A\00"
@.str.1 = [9 x i8] c"%02d.pic\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [29 x i8] c"hp2xx -- opening PIC file(s)\00"
define i32 @Init_PIC_files(i8* %0, i32** %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [80 x i8]
%13 = alloca [8 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %7
store i32** %1, i32*** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%17 = load i32, i32* %10
%18 = sub nsw i32 %17, 1
%19 = sdiv i32 %18, 400
%20 = add nsw i32 1, %19
store i32 %20, i32* %16
store i32 0, i32* %14
br label %21
21: ; preds = %103, %5
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %108
24: ; preds = %21
%25 = load i32**, i32*** %8
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
%29 = load i32*, i32** %28
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %42
31: ; preds = %24
%32 = load i32**, i32*** %8
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32*, i32** %32, i64 %34
%36 = load i32*, i32** %35
%37 = call i32 @fclose(i32* %36)
%38 = load i32**, i32*** %8
%39 = load i32, i32* %14
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
store i32* null, i32** %41
br label %42
42: ; preds = %31, %24
%43 = load i32, i32* %11
%44 = load i32, i32* %14
%45 = load i32, i32* %16
%46 = mul nsw i32 %44, %45
%47 = add nsw i32 %43, %46
store i32 %47, i32* %15
%48 = load i32, i32* %15
%49 = icmp sgt i32 %48, 99
br i1 %49, label %50, label %79
50: ; preds = %42
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %53
53: ; preds = %75, %50
%54 = load i32, i32* %14
%55 = icmp sgt i32 %54, -1
br i1 %55, label %56, label %78
56: ; preds = %53
%57 = load i32**, i32*** %8
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32*, i32** %57, i64 %59
%61 = load i32*, i32** %60
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %74
63: ; preds = %56
%64 = load i32**, i32*** %8
%65 = load i32, i32* %14
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32*, i32** %64, i64 %66
%68 = load i32*, i32** %67
%69 = call i32 @fclose(i32* %68)
%70 = load i32**, i32*** %8
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32*, i32** %70, i64 %72
store i32* null, i32** %73
br label %74
74: ; preds = %63, %56
br label %75
75: ; preds = %74
%76 = load i32, i32* %14
%77 = add nsw i32 %76, -1
store i32 %77, i32* %14
br label %53
78: ; preds = %53
store i32 -1, i32* %6
br label %109
79: ; preds = %42
%80 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%81 = load i32, i32* %15
%82 = call i32 @sprintf(i8* %80, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %81)
%83 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%84 = load i8*, i8** %7
%85 = call i32 @strcpy(i8* %83, i8* %84)
%86 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%87 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%88 = load i8*, i8** %7
%89 = call i32 @strlen(i8* %88)
%90 = sub nsw i32 80, %89
%91 = sub nsw i32 %90, 1
%92 = call i32 @strncat(i8* %86, i8* %87, i32 %91)
%93 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%94 = call i32* @fopen(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%95 = load i32**, i32*** %8
%96 = load i32, i32* %14
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32*, i32** %95, i64 %97
store i32* %94, i32** %98
%99 = icmp eq i32* %94, null
br i1 %99, label %100, label %102
100: ; preds = %79
%101 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %6
br label %109
102: ; preds = %79
br label %103
103: ; preds = %102
%104 = load i32, i32* %14
%105 = add nsw i32 %104, 1
store i32 %105, i32* %14
%106 = load i32, i32* %9
%107 = sub nsw i32 %106, 80
store i32 %107, i32* %9
br label %21
108: ; preds = %21
store i32 0, i32* %6
br label %109
109: ; preds = %108, %100, %78
%110 = load i32, i32* %6
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"ERROR: Too many PIC files per column!\0A\00"
@.str.1 = [9 x i8] c"%02d.pic\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [29 x i8] c"hp2xx -- opening PIC file(s)\00"
define i32 @Init_PIC_files(i8* %0, i32** nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [80 x i8]
%7 = alloca [8 x i8]
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%10 = add nsw i32 %3, -1
%11 = sdiv i32 %10, 400
%12 = add nsw i32 %11, 1
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %54
14: ; preds = %5, %50
%15 = phi i64 [ %51, %50 ], [ 0, %5 ]
%16 = phi i32 [ %52, %50 ], [ %2, %5 ]
%17 = getelementptr inbounds i32*, i32** %1, i64 %15
%18 = load i32*, i32** %17
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 @fclose(i32* %18)
store i32* null, i32** %17
br label %22
22: ; preds = %20, %14
%23 = trunc i64 %15 to i32
%24 = mul nsw i32 %12, %23
%25 = add nsw i32 %24, %4
%26 = icmp sgt i32 %25, 99
br i1 %26, label %27, label %40
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %27, %37
%31 = phi i64 [ %15, %27 ], [ %38, %37 ]
%32 = getelementptr inbounds i32*, i32** %1, i64 %31
%33 = load i32*, i32** %32
%34 = icmp eq i32* %33, null
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 @fclose(i32* %33)
store i32* null, i32** %32
br label %37
37: ; preds = %30, %35
%38 = add nsw i64 %31, -1
%39 = icmp sgt i64 %31, 0
br i1 %39, label %30, label %54
40: ; preds = %22
%41 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%42 = call i32 @strcpy(i8* %8, i8* %0)
%43 = call i32 @strlen(i8* %0)
%44 = sub i32 79, %43
%45 = call i32 @strncat(i8* %8, i8* %9, i32 %44)
%46 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %17
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %40
%49 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %54
50: ; preds = %40
%51 = add nuw nsw i64 %15, 1
%52 = add nsw i32 %16, -80
%53 = icmp sgt i32 %16, 80
br i1 %53, label %14, label %54
54: ; preds = %50, %37, %5, %48
%55 = phi i32 [ -1, %48 ], [ 0, %5 ], [ -1, %37 ], [ 0, %50 ]
ret i32 %55
}