#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*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int strcspn(char const *, char *);
int /*<<< orphan*/ xfwrite(char const *, int, int, int /*<<< orphan*/ *);
void conf_write_string(bool headerfile, const char *name, const char *str,
                       FILE *out) {
  int l;
  if (headerfile)
    fprintf(out, "#define %s%s \"", "CONFIG_", name);
  else
    fprintf(out, "%s%s=\"", "CONFIG_", name);
  while (1) {
    l = strcspn(str, "\"\\");
    if (l) {
      xfwrite(str, l, 1, out);
      str += l;
    }
    if (!*str)
      break;
    fprintf(out, "\\%c", *str++);
  }
  fputs("\"\n", out);
}


x86 assembly (clang, -O0):
<conf_write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1183 <conf_write_string+0x43>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    0xe90(%rip),%rsi
lea    0xe98(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11a0 <conf_write_string+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    0xe85(%rip),%rsi
lea    0xe76(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11a5 <conf_write_string+0x65>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11e8 <conf_write_string+0xa8>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1060 <xfwrite@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11fa <conf_write_string+0xba>
jmp    1224 <conf_write_string+0xe4>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbq (%rax),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11a5 <conf_write_string+0x65>
mov    -0x20(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1030 <fputs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conf_write_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rcx
test   %edi,%edi
lea    0xebd(%rip),%rax
lea    0xe9f(%rip),%rsi
cmove  %rax,%rsi
lea    0xea3(%rip),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xea1(%rip),%r15
lea    0xe9d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcspn@plt>
test   %eax,%eax
je     11b9 <conf_write_string+0x79>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <xfwrite@plt>
movslq %ebp,%rax
add    %rax,%rbx
movsbq (%rbx),%rdx
test   %rdx,%rdx
je     11d5 <conf_write_string+0x95>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1190 <conf_write_string+0x50>
lea    0xe49(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"#define %s%s \22\00"
@.str.1 = [8 x i8] c"CONFIG_\00"
@.str.2 = [7 x i8] c"%s%s=\22\00"
@.str.3 = [3 x i8] c"\22\\\00"
@.str.4 = [4 x i8] c"\\%c\00"
@.str.5 = [3 x i8] c"\22\0A\00"
define void @conf_write_string(i32 %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32*, i32** %8
%14 = load i8*, i8** %6
%15 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %20
16: ; preds = %4
%17 = load i32*, i32** %8
%18 = load i8*, i8** %6
%19 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20, %40
%22 = load i8*, i8** %7
%23 = call i32 @strcspn(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = load i32, i32* %9
%29 = load i32*, i32** %8
%30 = call i32 @xfwrite(i8* %27, i32 %28, i32 1, i32* %29)
%31 = load i32, i32* %9
%32 = load i8*, i8** %7
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %7
br label %35
35: ; preds = %26, %21
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = icmp ne i8 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35
br label %48
40: ; preds = %35
%41 = load i32*, i32** %8
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %7
%44 = load i8, i8* %42
%45 = sext i8 %44 to i64
%46 = inttoptr i64 %45 to i8*
%47 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %21
48: ; preds = %39
%49 = load i32*, i32** %8
%50 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"#define %s%s \22\00"
@.str.1 = [8 x i8] c"CONFIG_\00"
@.str.2 = [7 x i8] c"%s%s=\22\00"
@.str.3 = [3 x i8] c"\22\\\00"
@.str.4 = [4 x i8] c"\\%c\00"
@.str.5 = [3 x i8] c"\22\0A\00"
define void @conf_write_string(i32 %0, i8* %1, i8* %2, i32* %3) {
%5 = icmp eq i32 %0, 0
%6 = select i1 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0)
%7 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %3, i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %8
8: ; preds = %20, %4
%9 = phi i8* [ %2, %4 ], [ %21, %20 ]
%10 = tail call i32 @strcspn(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i32 @xfwrite(i8* %9, i32 %10, i32 1, i32* %3)
%14 = sext i32 %10 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
br label %16
16: ; preds = %12, %8
%17 = phi i8* [ %15, %12 ], [ %9, %8 ]
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = sext i8 %18 to i64
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %8
25: ; preds = %16
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %3)
ret void
}