#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int write_file_of_lines(const char filepath[], char *strs[], size_t nstrs) {
  FILE *fp;
  size_t i;
  if ((fp = fopen(filepath, "w")) == NULL) {
    return 1;
  }
  for (i = 0U; i < nstrs; i++) {
    fprintf(fp, "%s\n", strs[i]);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_file_of_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    116e <write_file_of_lines+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    11c1 <write_file_of_lines+0x91>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b1 <write_file_of_lines+0x81>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1176 <write_file_of_lines+0x46>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file_of_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1194 <write_file_of_lines+0x64>
mov    %rax,%r13
test   %r15,%r15
je     1188 <write_file_of_lines+0x58>
xor    %ebx,%ebx
lea    0xea1(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <write_file_of_lines+0x40>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1199 <write_file_of_lines+0x69>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @write_file_of_lines(i8* %0, i8** %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 1, i32* %4
br label %32
14: ; preds = %3
store i64 0, i64* %9
br label %15
15: ; preds = %26, %14
%16 = load i64, i64* %9
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32*, i32** %8
%21 = load i8**, i8*** %6
%22 = load i64, i64* %9
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %19
%27 = load i64, i64* %9
%28 = add i64 %27, 1
store i64 %28, i64* %9
br label %15
29: ; preds = %15
%30 = load i32*, i32** %8
%31 = call i32 @fclose(i32* %30)
store i32 0, i32* %4
br label %32
32: ; preds = %29, %13
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @write_file_of_lines(i8* nocapture %0, i8** nocapture %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = icmp eq i64 %2, 0
br i1 %7, label %15, label %8
8: ; preds = %6, %8
%9 = phi i64 [ %13, %8 ], [ 0, %6 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = add nuw i64 %9, 1
%14 = icmp eq i64 %13, %2
br i1 %14, label %15, label %8
15: ; preds = %8, %6
%16 = tail call i32 @fclose(i32* %4)
br label %17
17: ; preds = %3, %15
%18 = phi i32 [ 0, %15 ], [ 1, %3 ]
ret i32 %18
}