#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*/ printf(char *);
void saveDiagram(char busNumber[], int seats[], int arrayLength) {
  FILE *fpointer;
  fpointer = fopen("layout.txt", "w");
  int i = 0;
  int character = 1;
  fprintf(fpointer, busNumber);
  fprintf(fpointer, "\n");
  while (i < arrayLength) {
    if (character == 3 && (i + 5 <= arrayLength)) {
      fprintf(fpointer, " ");
    }
    if (character == 5 && (i + 5 <= arrayLength)) {
      fprintf(fpointer, "\n");
      character = 1;
    }
    if (seats[i] == 0) {
      fprintf(fpointer, "_");
    } else {
      fprintf(fpointer, "*");
    }
    i++;
    character++;
  }
  fclose(fpointer);
  printf("Bus diagram was saved in layout.txt\n");
}


x86 assembly (clang, -O0):
<saveDiagram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xea6(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1248 <saveDiagram+0x108>
cmpl   $0x3,-0x28(%rbp)
jne    11ca <saveDiagram+0x8a>
mov    -0x24(%rbp),%eax
add    $0x5,%eax
cmp    -0x14(%rbp),%eax
jg     11ca <saveDiagram+0x8a>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x5,-0x28(%rbp)
jne    11fa <saveDiagram+0xba>
mov    -0x24(%rbp),%eax
add    $0x5,%eax
cmp    -0x14(%rbp),%eax
jg     11fa <saveDiagram+0xba>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1221 <saveDiagram+0xe1>
mov    -0x20(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1231 <saveDiagram+0xf1>
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1195 <saveDiagram+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveDiagram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb0(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
test   %r12d,%r12d
jle    120f <saveDiagram+0xbf>
mov    %r12d,%r15d
mov    $0x1,%ebx
xor    %ebp,%ebp
jmp    11c4 <saveDiagram+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbp
add    $0x1,%ebx
cmp    %rbp,%r15
je     120f <saveDiagram+0xbf>
lea    0x5(%rbp),%eax
cmp    $0x3,%ebx
jne    11e0 <saveDiagram+0x90>
cmp    %r12d,%eax
jg     11e0 <saveDiagram+0x90>
mov    $0x3,%ebx
mov    $0x20,%edi
jmp    11f4 <saveDiagram+0xa4>
nopl   (%rax)
cmp    $0x5,%ebx
jne    11fc <saveDiagram+0xac>
cmp    %r12d,%eax
jg     11fc <saveDiagram+0xac>
mov    $0x1,%ebx
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
cmpl   $0x0,(%r14,%rbp,4)
mov    $0x5f,%edi
je     11b0 <saveDiagram+0x60>
mov    $0x2a,%edi
jmp    11b0 <saveDiagram+0x60>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xde4(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"layout.txt\00"
@.str.1 = [2 x i8] c"w\00"
@str = [36 x i8] c"Bus diagram was saved in layout.txt\00"
define void @saveDiagram(i8* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @fprintf(i32* %4, i8* %0)
%6 = tail call i32 @fputc(i32 10, i32* %4)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %35
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %25
%11 = phi i64 [ 0, %8 ], [ %32, %25 ]
%12 = phi i32 [ 1, %8 ], [ %33, %25 ]
%13 = icmp ne i32 %12, 3
%14 = trunc i64 %11 to i32
%15 = add i32 %14, 5
%16 = icmp sgt i32 %15, %2
%17 = select i1 %13, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = icmp ne i32 %12, 5
%20 = select i1 %19, i1 true, i1 %16
br i1 %20, label %25, label %21
21: ; preds = %18, %10
%22 = phi i32 [ 32, %10 ], [ 10, %18 ]
%23 = phi i32 [ 3, %10 ], [ 1, %18 ]
%24 = tail call i32 @fputc(i32 %22, i32* %4)
br label %25
25: ; preds = %21, %18
%26 = phi i32 [ %12, %18 ], [ %23, %21 ]
%27 = getelementptr inbounds i32, i32* %1, i64 %11
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 95, i32 42
%31 = tail call i32 @fputc(i32 %30, i32* %4)
%32 = add nuw nsw i64 %11, 1
%33 = add nsw i32 %26, 1
%34 = icmp eq i64 %32, %9
br i1 %34, label %35, label %10
35: ; preds = %25, %3
%36 = tail call i32 @fclose(i32* %4)
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
ret void
}