#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*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *openFileForWriting(char const *);
void writeStringArrayToFile(const char *file, char **strings,
                            const unsigned numStrings) {
  FILE *targetFile = openFileForWriting(file);
  for (unsigned i = 0; i < numStrings; i++) {
    fputs(strings[i], targetFile);
  }
  fclose(targetFile);
}


x86 assembly (clang, -O0):
<writeStringArrayToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <openFileForWriting@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1185 <writeStringArrayToFile+0x55>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1157 <writeStringArrayToFile+0x27>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeStringArrayToFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
call   1050 <openFileForWriting@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     1165 <writeStringArrayToFile+0x35>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <writeStringArrayToFile+0x20>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
define void @writeStringArrayToFile(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @openFileForWriting(i8* %9)
store i32* %10, i32** %7
store i32 0, i32* %8
br label %11
11: ; preds = %23, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = load i32*, i32** %7
%22 = call i32 @fputs(i8* %20, i32* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %8
%25 = add i32 %24, 1
store i32 %25, i32* %8
br label %11
26: ; preds = %11
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
define void @writeStringArrayToFile(i8* %0, i8** nocapture %1, i32 %2) {
%4 = tail call i32* @openFileForWriting(i8* %0)
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %10
8: ; preds = %10, %3
%9 = tail call i32 @fclose(i32* %4)
ret void
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %15, %10 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @fputs(i8* %13, i32* %4)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %8, label %10
}