#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*/ def;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_path(char *);
int /*<<< orphan*/ printf(char *, char *);
int writeconfig(void) {
  FILE *config;
  char *path;
  unsigned int i;
  char *def[] = {"# cas config file\n",
                 "#\n",
                 "# font - full path to a ttf font\n",
                 "# font_size - size the font\n",
                 "# source_image - image where the text will be written\n",
                 "# *_line - x,y,[1/0] enabled or disabled\n\n",
                 "font /usr/share/fonts/corefonts/times.ttf\n",
                 "font_size 10.5\n",
                 "source_image /usr/share/cas/stat.png\n",
                 "first_line 23,17,1\n",
                 "second_line 23,34,1\n",
                 "third_line 23,51,1\n",
                 "fourth_line 23,68,1\n",
                 "fifth_line 23,85,1\n",
                 "sixth_line 23,102,1\n",
                 "seventh_line 23,119,1\n",
                 "template /usr/share/cas/tmp.html\n"
                 "img_type 0\n"};
  path = get_path("casrc");
  if (path == NULL)
    return 0;
  if ((config = fopen(path, "w")) == NULL)
    return 0;
  for (i = 0; i < sizeof(def) / sizeof(char *); i++)
    fprintf(config, "%s", def[i]);
  fclose(config);
  printf("%s created, please edit it and then rerun cas\n", path);
  free(path);
  return 1;
}


x86 assembly (clang, -O0):
<writeconfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0xb0(%rbp),%rdi
lea    0x2c07(%rip),%rsi
mov    $0x88,%edx
call   1070 <memcpy@plt>
lea    0x103d(%rip),%rdi
call   1080 <get_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <writeconfig+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    124a <writeconfig+0xda>
mov    -0x18(%rbp),%rdi
lea    0x1018(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e4 <writeconfig+0x74>
movl   $0x0,-0x4(%rbp)
jmp    124a <writeconfig+0xda>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    $0x11,%rax
jae    1221 <writeconfig+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    -0xb0(%rbp,%rax,8),%rdx
ff
lea    0xfd1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11eb <writeconfig+0x7b>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rsi
lea    0xfad(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeconfig>:
push   %rbp
push   %r14
push   %rbx
lea    0x106c(%rip),%rdi
call   1060 <get_path@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1366 <writeconfig+0x206>
mov    %rax,%r14
lea    0x1058(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1366 <writeconfig+0x206>
mov    %rax,%rbx
lea    0xe60(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe5a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe44(%rip),%rdi
mov    $0x21,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe4d(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe51(%rip),%rdi
mov    $0x36,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe6f(%rip),%rdi
mov    $0x2a,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe81(%rip),%rdi
mov    $0x2a,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe93(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe8a(%rip),%rdi
mov    $0x25,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe97(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe92(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe8e(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe89(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe85(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe80(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe7c(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe7a(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe8e(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"# cas config file\0A\00"
@.str.1 = [3 x i8] c"#\0A\00"
@.str.2 = [34 x i8] c"# font - full path to a ttf font\0A\00"
@.str.3 = [29 x i8] c"# font_size - size the font\0A\00"
@.str.4 = [55 x i8] c"# source_image - image where the text will be written\0A\00"
@.str.5 = [43 x i8] c"# *_line - x,y,[1/0] enabled or disabled\0A\0A\00"
@.str.6 = [43 x i8] c"font /usr/share/fonts/corefonts/times.ttf\0A\00"
@.str.7 = [16 x i8] c"font_size 10.5\0A\00"
@.str.8 = [38 x i8] c"source_image /usr/share/cas/stat.png\0A\00"
@.str.9 = [20 x i8] c"first_line 23,17,1\0A\00"
@.str.10 = [21 x i8] c"second_line 23,34,1\0A\00"
@.str.11 = [20 x i8] c"third_line 23,51,1\0A\00"
@.str.12 = [21 x i8] c"fourth_line 23,68,1\0A\00"
@.str.13 = [20 x i8] c"fifth_line 23,85,1\0A\00"
@.str.14 = [21 x i8] c"sixth_line 23,102,1\0A\00"
@.str.15 = [23 x i8] c"seventh_line 23,119,1\0A\00"
@.str.16 = [45 x i8] c"template /usr/share/cas/tmp.html\0Aimg_type 0\0A\00"
@__const.writeconfig.def = [17 x i8*] [i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.16, i32 0, i32 0)]
@.str.17 = [6 x i8] c"casrc\00"
@.str.18 = [2 x i8] c"w\00"
@.str.19 = [3 x i8] c"%s\00"
@.str.20 = [47 x i8] c"%s created, please edit it and then rerun cas\0A\00"
define i32 @writeconfig() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [17 x i8*]
%6 = bitcast [17 x i8*]* %5 to i8*
%7 = call i8* @get_path(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %38
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
store i32* %13, i32** %2
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %1
br label %38
16: ; preds = %11
store i32 0, i32* %4
br label %17
17: ; preds = %28, %16
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = icmp ult i64 %19, 17
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8*], [17 x i8*]* %5, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add i32 %29, 1
store i32 %30, i32* %4
br label %17
31: ; preds = %17
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
%34 = load i8*, i8** %3
%35 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.20, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
store i32 1, i32* %1
br label %38
38: ; preds = %31, %15, %10
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [19 x i8] c"# cas config file\0A\00"
@.str.1 = [3 x i8] c"#\0A\00"
@.str.2 = [34 x i8] c"# font - full path to a ttf font\0A\00"
@.str.3 = [29 x i8] c"# font_size - size the font\0A\00"
@.str.4 = [55 x i8] c"# source_image - image where the text will be written\0A\00"
@.str.5 = [43 x i8] c"# *_line - x,y,[1/0] enabled or disabled\0A\0A\00"
@.str.6 = [43 x i8] c"font /usr/share/fonts/corefonts/times.ttf\0A\00"
@.str.7 = [16 x i8] c"font_size 10.5\0A\00"
@.str.8 = [38 x i8] c"source_image /usr/share/cas/stat.png\0A\00"
@.str.9 = [20 x i8] c"first_line 23,17,1\0A\00"
@.str.10 = [21 x i8] c"second_line 23,34,1\0A\00"
@.str.11 = [20 x i8] c"third_line 23,51,1\0A\00"
@.str.12 = [21 x i8] c"fourth_line 23,68,1\0A\00"
@.str.13 = [20 x i8] c"fifth_line 23,85,1\0A\00"
@.str.14 = [21 x i8] c"sixth_line 23,102,1\0A\00"
@.str.15 = [23 x i8] c"seventh_line 23,119,1\0A\00"
@.str.16 = [45 x i8] c"template /usr/share/cas/tmp.html\0Aimg_type 0\0A\00"
@.str.17 = [6 x i8] c"casrc\00"
@.str.18 = [2 x i8] c"w\00"
@.str.20 = [47 x i8] c"%s created, please edit it and then rerun cas\0A\00"
define i32 @writeconfig() {
%1 = tail call i8* @get_path(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %27, label %3
3: ; preds = %0
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 18, i64 1, i32* %4)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %4)
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 33, i64 1, i32* %4)
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 28, i64 1, i32* %4)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i64 54, i64 1, i32* %4)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i64 42, i64 1, i32* %4)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i64 42, i64 1, i32* %4)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 15, i64 1, i32* %4)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i64 37, i64 1, i32* %4)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i64 19, i64 1, i32* %4)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i64 20, i64 1, i32* %4)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i64 19, i64 1, i32* %4)
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0), i64 20, i64 1, i32* %4)
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i64 19, i64 1, i32* %4)
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0), i64 20, i64 1, i32* %4)
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i64 22, i64 1, i32* %4)
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.16, i64 0, i64 0), i64 44, i64 1, i32* %4)
%24 = tail call i32 @fclose(i32* %4)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.20, i64 0, i64 0), i8* %1)
%26 = tail call i32 @free(i8* %1)
br label %27
27: ; preds = %3, %0, %6
%28 = phi i32 [ 1, %6 ], [ 0, %0 ], [ 0, %3 ]
ret i32 %28
}