#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*/);
void cfg_writeconfig(char **data, char *configfile) {
  FILE *cfg;
  if ((cfg = fopen(configfile, "w")) == NULL) {
    return;
  }
  while (*data) {
    fprintf(cfg, "%s\n", *data++);
  }
  fclose(cfg);
}


x86 assembly (clang, -O0):
<cfg_writeconfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1163 <cfg_writeconfig+0x33>
jmp    11a8 <cfg_writeconfig+0x78>
jmp    1168 <cfg_writeconfig+0x38>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     119f <cfg_writeconfig+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1168 <cfg_writeconfig+0x38>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_writeconfig>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xebe(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1194 <cfg_writeconfig+0x64>
mov    %rax,%r14
mov    (%rbx),%rdx
test   %rdx,%rdx
je     1187 <cfg_writeconfig+0x57>
add    $0x8,%rbx
lea    0xe9d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%rdx
add    $0x8,%rbx
test   %rdx,%rdx
jne    1170 <cfg_writeconfig+0x40>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
pop    %rbx
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 void @cfg_writeconfig(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %25
10: ; preds = %2
br label %11
11: ; preds = %15, %10
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i8**, i8*** %3
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %3
%19 = load i8*, i8** %17
%20 = ptrtoint i8* %19 to i32
%21 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %11
22: ; preds = %11
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %9
ret void
}

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