#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char, ...);
short *make_pair_table(char *);
int /*<<< orphan*/ nrerror(char *);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void write_ct_file(char *fname, char *sequence, char *structure, char *name,
                   float energy) {
  int i, length;
  short *table;
  FILE *ct;
  length = strlen(structure);
  if ((table = make_pair_table(structure)) == NULL) {
    return;
  }
  if (length != strlen(sequence))
    nrerror("sequence and structure have unequal length");
  if (strcmp(fname, "-") == 0)
    ct = stdout;
  else {
    ct = fopen(fname, "a");
    if (ct == NULL)
      nrerror("can't open .ct file");
  }
  fprintf(ct, "%5d ENERGY = %7.1f    %s\n", length, energy, name);
  for (i = 1; i <= length; i++)
    fprintf(ct, "%5d %c   %5d %4d %4d %4d\n", i, sequence[i - 1], i - 1,
            (i + 1) % (length + 1), table[i], i);
  if (strcmp(fname, "-"))
    fclose(ct);
  else
    fflush(ct);
}


x86 assembly (clang, -O0):
<write_ct_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <make_pair_table@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11c5 <write_ct_file+0x45>
jmp    1321 <write_ct_file+0x1a1>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
je     11ed <write_ct_file+0x6d>
lea    0xe18(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121a <write_ct_file+0x9a>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    124a <write_ct_file+0xca>
mov    -0x8(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1245 <write_ct_file+0xc5>
lea    0xdef(%rip),%rdi
call   1030 <nrerror@plt>
jmp    124a <write_ct_file+0xca>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%edx
movss  -0x24(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    -0x20(%rbp),%r8
lea    0xdde(%rip),%rsi
movsbl %al,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     12f0 <write_ct_file+0x170>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%r8d
sub    $0x1,%r8d
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
cltd
idiv   %esi
mov    %edx,%r9d
mov    -0x48(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rsi
movswl (%rax,%rsi,2),%r10d
mov    -0x28(%rbp),%eax
lea    0xd8d(%rip),%rsi
movsbl %cl,%ecx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1276 <write_ct_file+0xf6>
mov    -0x8(%rbp),%rdi
lea    0xd30(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1318 <write_ct_file+0x198>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1321 <write_ct_file+0x1a1>
mov    -0x40(%rbp),%rdi
call   1080 <fflush@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ct_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movss  %xmm0,0x8(%rsp)
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1090 <make_pair_table@plt>
test   %rax,%rax
je     1211 <write_ct_file+0x91>
mov    %rax,%r12
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r15d
je     11d4 <write_ct_file+0x54>
lea    0xe31(%rip),%rdi
call   1030 <nrerror@plt>
lea    0xe50(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
mov    %rbp,0x10(%rsp)
je     1220 <write_ct_file+0xa0>
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    122a <write_ct_file+0xaa>
lea    0xe27(%rip),%rdi
call   1030 <nrerror@plt>
xor    %eax,%eax
jmp    122a <write_ct_file+0xaa>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db9(%rip),%rax
mov    (%rax),%rax
cvttss2si 0x8(%rsp),%ecx
movsbl %cl,%ecx
lea    0xe09(%rip),%rsi
mov    %rax,%rdi
mov    %rax,0x8(%rsp)
mov    %r15d,%edx
mov    %r13,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r15d,%r15d
jle    12b0 <write_ct_file+0x130>
mov    %r14,%r13
mov    %r15d,%ebx
add    $0x1,%r15d
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%r8),%r14
movsbl 0x0(%r13,%r8,1),%ecx
lea    0x2(%r8),%eax
cltd
idiv   %r15d
mov    %edx,%r9d
movswl 0x2(%r12,%r8,2),%ebp
mov    0x8(%rsp),%rdi
lea    0xdc6(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
push   %r14
push   %rbp
call   1070 <fprintf@plt>
add    $0x10,%rsp
mov    %r14,%r8
cmp    %r14,%rbx
jne    1270 <write_ct_file+0xf0>
mov    0x8(%rsp),%rbx
lea    0xd6f(%rip),%rsi
mov    0x10(%rsp),%rdi
call   1060 <strcmp@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
test   %rax,%rax
je     12e1 <write_ct_file+0x161>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fflush@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"sequence and structure have unequal length\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"can't open .ct file\00"
@.str.4 = [26 x i8] c"%5d ENERGY = %7.1f %s\0A\00"
@.str.5 = [26 x i8] c"%5d %c %5d %4d %4d %4d\0A\00"
define void @write_ct_file(i8* %0, i8* %1, i8* %2, i8* %3, float %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
%13 = alloca i16*
%14 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store float %4, float* %10
%15 = load i8*, i8** %8
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %12
%17 = load i8*, i8** %8
%18 = call i16* @make_pair_table(i8* %17)
store i16* %18, i16** %13
%19 = icmp eq i16* %18, null
br i1 %19, label %20, label %21
20: ; preds = %5
br label %90
21: ; preds = %5
%22 = load i32, i32* %12
%23 = load i8*, i8** %7
%24 = call i32 @strlen(i8* %23)
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @nrerror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = load i8*, i8** %6
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i32*, i32** @stdout
store i32* %33, i32** %14
br label %42
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %36, i32** %14
%37 = load i32*, i32** %14
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @nrerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
br label %42
42: ; preds = %41, %32
%43 = load i32*, i32** %14
%44 = load i32, i32* %12
%45 = load float, float* %10
%46 = fptosi float %45 to i8
%47 = load i8*, i8** %9
%48 = call i32 (i32*, i8*, i32, i8, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %44, i8 signext %46, i8* %47)
store i32 1, i32* %11
br label %49
49: ; preds = %77, %42
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = icmp sle i32 %50, %51
br i1 %52, label %53, label %80
53: ; preds = %49
%54 = load i32*, i32** %14
%55 = load i32, i32* %11
%56 = load i8*, i8** %7
%57 = load i32, i32* %11
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
%61 = load i8, i8* %60
%62 = load i32, i32* %11
%63 = sub nsw i32 %62, 1
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
%68 = srem i32 %65, %67
%69 = load i16*, i16** %13
%70 = load i32, i32* %11
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i16, i16* %69, i64 %71
%73 = load i16, i16* %72
%74 = sext i16 %73 to i32
%75 = load i32, i32* %11
%76 = call i32 (i32*, i8*, i32, i8, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %55, i8 signext %61, i32 %63, i32 %68, i32 %74, i32 %75)
br label %77
77: ; preds = %53
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %49
80: ; preds = %49
%81 = load i8*, i8** %6
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = load i32*, i32** %14
%86 = call i32 @fclose(i32* %85)
br label %90
87: ; preds = %80
%88 = load i32*, i32** %14
%89 = call i32 @fflush(i32* %88)
br label %90
90: ; preds = %20, %87, %84
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"sequence and structure have unequal length\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"can't open .ct file\00"
@.str.4 = [26 x i8] c"%5d ENERGY = %7.1f %s\0A\00"
@.str.5 = [26 x i8] c"%5d %c %5d %4d %4d %4d\0A\00"
define void @write_ct_file(i8* %0, i8* %1, i8* %2, i8* %3, float %4) {
%6 = tail call i32 @strlen(i8* %2)
%7 = tail call i16* @make_pair_table(i8* %2)
%8 = icmp eq i16* %7, null
br i1 %8, label %54, label %9
9: ; preds = %5
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp eq i32 %6, %10
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @nrerror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32*, i32** @stdout
br label %24
19: ; preds = %14
%20 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @nrerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %19, %22, %17
%25 = phi i32* [ %18, %17 ], [ null, %22 ], [ %20, %19 ]
%26 = fptosi float %4 to i8
%27 = tail call i32 (i32*, i8*, i32, i8, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %6, i8 signext %26, i8* %3)
%28 = icmp slt i32 %6, 1
br i1 %28, label %47, label %29
29: ; preds = %24
%30 = add nuw nsw i32 %6, 1
%31 = zext i32 %30 to i64
br label %32
32: ; preds = %29, %32
%33 = phi i64 [ 1, %29 ], [ %39, %32 ]
%34 = trunc i64 %33 to i32
%35 = add nsw i64 %33, -1
%36 = add nsw i32 %34, -1
%37 = getelementptr inbounds i8, i8* %1, i64 %35
%38 = load i8, i8* %37
%39 = add nuw nsw i64 %33, 1
%40 = trunc i64 %39 to i32
%41 = srem i32 %40, %30
%42 = getelementptr inbounds i16, i16* %7, i64 %33
%43 = load i16, i16* %42
%44 = sext i16 %43 to i32
%45 = tail call i32 (i32*, i8*, i32, i8, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %34, i8 signext %38, i32 %36, i32 %41, i32 %44, i32 %34)
%46 = icmp eq i64 %39, %31
br i1 %46, label %47, label %32
47: ; preds = %32, %24
%48 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = tail call i32 @fclose(i32* %25)
br label %54
52: ; preds = %47
%53 = tail call i32 @fflush(i32* %25)
br label %54
54: ; preds = %50, %52, %5
ret void
}