#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int, float);
int /*<<< orphan*/ stdout;
void writefiles(char path[], char s[], unsigned char result[5][512][512],
                float sigma, int pic_t, int pic_x, int pic_y, int start,
                int end, unsigned char header[32]) {
  char fname[100];
  int i, j, time, no_bytes;
  FILE *fd;
  if (sigma == 0.0)
    return;
  printf("\nWriting smoothed files...\n");
  time = -1;
  for (i = start; i <= end; i++) {
    no_bytes = 0;
    time++;
    sprintf(fname, "%s/smoothed.%s%d-%3.1f", path, s, i, sigma);
    if ((fd = fopen(fname, "wb")) != NULL) {
      no_bytes += fwrite(&header[0], sizeof(unsigned char), 32, fd);
      for (j = 0; j < pic_x; j++)
        no_bytes +=
            fwrite(&result[time][j][0], sizeof(unsigned char), pic_y, fd);
      printf("File %s written (%d bytes)\n", fname, no_bytes);
    } else {
      printf("File %s cannot be written\n", fname);
      exit(1);
    }
    fflush(stdout);
    fclose(fd);
  }
}


x86 assembly (clang, -O0):
<writefiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c2 <writefiles+0x52>
jp     11c2 <writefiles+0x52>
jmp    1364 <writefiles+0x1f4>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x9c(%rbp)
ff ff ff
mov    0x10(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    0x18(%rbp),%eax
jg     1364 <writefiles+0x1f4>
movl   $0x0,-0xa0(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x94(%rbp),%r8d
movss  -0x1c(%rbp),%xmm0
lea    0xdef(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
je     1317 <writefiles+0x1a7>
mov    0x20(%rbp),%rdi
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1090 <fwrite@plt>
mov    %rax,%rcx
movslq -0xa0(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa0(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12f7 <writefiles+0x187>
mov    -0x18(%rbp),%rdi
movslq -0x9c(%rbp),%rax
shl    $0x12,%rax
add    %rax,%rdi
movslq -0x98(%rbp),%rax
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%edx
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %rax,%rcx
movslq -0xa0(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa0(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    128d <writefiles+0x11d>
lea    -0x90(%rbp),%rsi
mov    -0xa0(%rbp),%edx
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1336 <writefiles+0x1c6>
lea    -0x90(%rbp),%rsi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11e3 <writefiles+0x73>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writefiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r8d,0x8(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,0x20(%rsp)
xorps  %xmm1,%xmm1
movss  %xmm0,0xc(%rsp)
ucomiss %xmm1,%xmm0
jne    11b0 <writefiles+0x30>
jnp    11db <writefiles+0x5b>
mov    %r9d,%ebx
mov    %rdx,%r13
mov    0xe8(%rsp),%r14d
mov    0xe0(%rsp),%ebp
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
sub    %ebp,%r14d
mov    %r14,0x18(%rsp)
jge    11ed <writefiles+0x6d>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%eax
mov    %rax,0x10(%rsp)
mov    $0xffffffffffffffff,%r14
lea    0x40(%rsp),%r15
jmp    125a <writefiles+0xda>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe03(%rip),%rdi
lea    0x40(%rsp),%r15
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebp
mov    0x38(%rsp),%r13
add    $0x40000,%r13
mov    0x30(%rsp),%r14
cmp    0x18(%rsp),%r14
je     11db <writefiles+0x5b>
mov    %r15,%rdi
lea    0xd9c(%rip),%rsi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    %ebp,%r8d
movss  0xc(%rsp),%xmm0
call   1080 <sprintf@plt>
mov    %r15,%rdi
lea    0xd91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12fa <writefiles+0x17a>
mov    %rax,%r12
add    $0x1,%r14
mov    %r14,0x30(%rsp)
mov    0xf0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rax,%r14
cmpl   $0x0,0x8(%rsp)
mov    %r13,0x38(%rsp)
jle    1210 <writefiles+0x90>
mov    0x10(%rsp),%r15
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
movslq %r14d,%r14
add    %rax,%r14
add    $0x200,%r13
add    $0xffffffffffffffff,%r15
jne    12d0 <writefiles+0x150>
jmp    1210 <writefiles+0x90>
lea    0xd35(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"\0AWriting smoothed files...\0A\00"
@.str.1 = [23 x i8] c"%s/smoothed.%s%d-%3.1f\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [28 x i8] c"File %s written (%d bytes)\0A\00"
@.str.4 = [27 x i8] c"File %s cannot be written\0A\00"
@stdout = global i32 0
define void @writefiles(i8* %0, i8* %1, [512 x [512 x i8]]* %2, float %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i8* %9) {
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [512 x [512 x i8]]*
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca [100 x i8]
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32*
store i8* %0, i8** %11
store i8* %1, i8** %12
store [512 x [512 x i8]]* %2, [512 x [512 x i8]]** %13
store float %3, float* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i8* %9, i8** %20
%27 = load float, float* %14
%28 = fpext float %27 to double
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %30, label %31
30: ; preds = %10
br label %98
31: ; preds = %10
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %24
%33 = load i32, i32* %18
store i32 %33, i32* %22
br label %34
34: ; preds = %95, %31
%35 = load i32, i32* %22
%36 = load i32, i32* %19
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %98
38: ; preds = %34
store i32 0, i32* %25
%39 = load i32, i32* %24
%40 = add nsw i32 %39, 1
store i32 %40, i32* %24
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%42 = load i8*, i8** %11
%43 = load i8*, i8** %12
%44 = load i32, i32* %22
%45 = load float, float* %14
%46 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43, i32 %44, float %45)
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %48, i32** %26
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %86
50: ; preds = %38
%51 = load i8*, i8** %20
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i32*, i32** %26
%54 = call i64 @fwrite(i8* %52, i32 1, i32 32, i32* %53)
%55 = load i32, i32* %25
%56 = sext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %25
store i32 0, i32* %23
br label %59
59: ; preds = %79, %50
%60 = load i32, i32* %23
%61 = load i32, i32* %16
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %82
63: ; preds = %59
%64 = load [512 x [512 x i8]]*, [512 x [512 x i8]]** %13
%65 = load i32, i32* %24
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [512 x [512 x i8]], [512 x [512 x i8]]* %64, i64 %66
%68 = load i32, i32* %23
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [512 x [512 x i8]], [512 x [512 x i8]]* %67, i64 0, i64 %69
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %70, i64 0, i64 0
%72 = load i32, i32* %17
%73 = load i32*, i32** %26
%74 = call i64 @fwrite(i8* %71, i32 1, i32 %72, i32* %73)
%75 = load i32, i32* %25
%76 = sext i32 %75 to i64
%77 = add nsw i64 %76, %74
%78 = trunc i64 %77 to i32
store i32 %78, i32* %25
br label %79
79: ; preds = %63
%80 = load i32, i32* %23
%81 = add nsw i32 %80, 1
store i32 %81, i32* %23
br label %59
82: ; preds = %59
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%84 = load i32, i32* %25
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %83, i32 %84)
br label %90
86: ; preds = %38
%87 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %87)
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %82
%91 = load i32, i32* @stdout
%92 = call i32 @fflush(i32 %91)
%93 = load i32*, i32** %26
%94 = call i32 @fclose(i32* %93)
br label %95
95: ; preds = %90
%96 = load i32, i32* %22
%97 = add nsw i32 %96, 1
store i32 %97, i32* %22
br label %34
98: ; preds = %30, %34
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"%s/smoothed.%s%d-%3.1f\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [28 x i8] c"File %s written (%d bytes)\0A\00"
@.str.4 = [27 x i8] c"File %s cannot be written\0A\00"
@stdout = global i32 0
@str = [27 x i8] c"\0AWriting smoothed files...\00"
define void @writefiles(i8* %0, i8* %1, [512 x [512 x i8]]* nocapture %2, float %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i8* nocapture %9) {
%11 = alloca [100 x i8]
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%13 = fcmp oeq float %3, 0.000000e+00
br i1 %13, label %53, label %14
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%16 = icmp slt i32 %8, %7
br i1 %16, label %53, label %17
17: ; preds = %14
%18 = icmp sgt i32 %5, 0
%19 = sub i32 %8, %7
%20 = zext i32 %19 to i64
%21 = zext i32 %5 to i64
br label %22
22: ; preds = %17, %41
%23 = phi i64 [ -1, %17 ], [ %25, %41 ]
%24 = phi i32 [ %7, %17 ], [ %48, %41 ]
%25 = add nsw i64 %23, 1
%26 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i32 %24, float %3)
%27 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %50, label %29
29: ; preds = %22
%30 = call i64 @fwrite(i8* %9, i32 1, i32 32, i32* %27)
br i1 %18, label %31, label %41
31: ; preds = %29, %31
%32 = phi i64 [ %39, %31 ], [ 0, %29 ]
%33 = phi i64 [ %38, %31 ], [ %30, %29 ]
%34 = getelementptr inbounds [512 x [512 x i8]], [512 x [512 x i8]]* %2, i64 %25, i64 %32, i64 0
%35 = call i64 @fwrite(i8* %34, i32 1, i32 %6, i32* %27)
%36 = shl i64 %33, 32
%37 = ashr exact i64 %36, 32
%38 = add nsw i64 %35, %37
%39 = add nuw nsw i64 %32, 1
%40 = icmp eq i64 %39, %21
br i1 %40, label %41, label %31
41: ; preds = %31, %29
%42 = phi i64 [ %30, %29 ], [ %38, %31 ]
%43 = trunc i64 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 %43)
%45 = load i32, i32* @stdout
%46 = call i32 @fflush(i32 %45)
%47 = call i32 @fclose(i32* %27)
%48 = add nsw i32 %24, 1
%49 = icmp eq i64 %25, %20
br i1 %49, label %53, label %22
50: ; preds = %22
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %41, %14, %10
ret void
}