#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 *, ...);
void write_option(FILE *f, const char *name, const char *chr) {
  fprintf(f, "%s='", name);
  while (*chr) {
    switch (*chr) {
    case '!':
    case '\'':
      fprintf(f, "'\\%c'", *chr);
      break;
    default:
      fprintf(f, "%c", *chr);
      break;
    }
    ++chr;
  }
  fprintf(f, "'\n");
}


x86 assembly (clang, -O0):
<write_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xecd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b8 <write_option+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x21,%eax
je     1170 <write_option+0x60>
jmp    115f <write_option+0x4f>
mov    -0x1c(%rbp),%eax
sub    $0x27,%eax
jne    118e <write_option+0x7e>
jmp    1170 <write_option+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11a7 <write_option+0x97>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113a <write_option+0x2a>
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_option>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %rdi,%r14
lea    0xebb(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%al
test   %al,%al
je     1191 <write_option+0x61>
add    $0x1,%rbx
lea    0xea8(%rip),%r15
jmp    1178 <write_option+0x48>
nop
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1191 <write_option+0x61>
movsbl %al,%edx
cmp    $0x27,%edx
je     1160 <write_option+0x30>
cmp    $0x21,%edx
je     1160 <write_option+0x30>
mov    %edx,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    116d <write_option+0x3d>
lea    0xe73(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fwrite@plt>

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

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