#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*/ fatal_error(int, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void save_file(FILE *file, char *str) {
  if (!str)
    return;
  if (!file) {
    fatal_error(-1, "could not open output file.");
    return;
  }
  int index = 0;
  while (str[index] != '\0') {
    if (index % 80 == 0 && index != 0) {
      fputc('\n', file);
    }
    fputc(str[index], file);
    index++;
  }
}


x86 assembly (clang, -O0):
<save_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1140 <save_file+0x20>
jmp    11ce <save_file+0xae>
cmpq   $0x0,-0x8(%rbp)
jne    1161 <save_file+0x41>
mov    $0xffffffff,%edi
lea    0xea9(%rip),%rsi
call   1040 <fatal_error@plt>
jmp    11ce <save_file+0xae>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ce <save_file+0xae>
mov    -0x14(%rbp),%eax
mov    $0x50,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a9 <save_file+0x89>
cmpl   $0x0,-0x14(%rbp)
je     11a9 <save_file+0x89>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <save_file+0x48>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     119d <save_file+0x7d>
mov    %rdi,%r14
test   %rdi,%rdi
je     11a7 <save_file+0x87>
mov    %rsi,%r15
mov    (%rsi),%al
test   %al,%al
je     119d <save_file+0x7d>
xor    %r13d,%r13d
mov    $0xcccccccd,%r12d
xor    %ebx,%ebx
jmp    116d <save_file+0x4d>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
add    $0x1,%r13d
test   %al,%al
je     119d <save_file+0x7d>
test   %rbx,%rbx
je     1150 <save_file+0x30>
mov    %r13d,%ecx
imul   %r12,%rcx
shr    $0x26,%rcx
shl    $0x4,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %ebx,%edx
sub    %ecx,%edx
jne    1150 <save_file+0x30>
mov    $0xa,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
movzbl (%r15,%rbx,1),%eax
jmp    1150 <save_file+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe52(%rip),%rsi
mov    $0xffffffff,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fatal_error@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"could not open output file.\00"
define void @save_file(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
br label %43
9: ; preds = %2
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @fatal_error(i32 -1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %43
14: ; preds = %9
store i32 0, i32* %5
br label %15
15: ; preds = %33, %14
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %15
%24 = load i32, i32* %5
%25 = srem i32 %24, 80
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32*, i32** %3
%32 = call i32 @fputc(i8 signext 10, i32* %31)
br label %33
33: ; preds = %30, %27, %23
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i32*, i32** %3
%40 = call i32 @fputc(i8 signext %38, i32* %39)
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %15
43: ; preds = %8, %12, %15
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"could not open output file.\00"
define void @save_file(i32* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %30, label %4
4: ; preds = %2
%5 = icmp eq i32* %0, null
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %30, label %11
9: ; preds = %4
%10 = tail call i32 @fatal_error(i32 -1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %30
11: ; preds = %6, %23
%12 = phi i8 [ %28, %23 ], [ %7, %6 ]
%13 = phi i64 [ %26, %23 ], [ 0, %6 ]
%14 = phi i8* [ %27, %23 ], [ %1, %6 ]
%15 = trunc i64 %13 to i32
%16 = urem i32 %15, 80
%17 = icmp eq i32 %16, 0
%18 = icmp ne i64 %13, 0
%19 = and i1 %18, %17
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = tail call i32 @fputc(i8 signext 10, i32* %0)
%22 = load i8, i8* %14
br label %23
23: ; preds = %20, %11
%24 = phi i8 [ %22, %20 ], [ %12, %11 ]
%25 = tail call i32 @fputc(i8 signext %24, i32* %0)
%26 = add nuw i64 %13, 1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %11
30: ; preds = %23, %6, %2, %9
ret void
}