#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*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "Not enough arguments");
    return -1;
  }
  {
    char path[256];
    char body[256];
    FILE *file;
    sprintf(path, "%s", argv[1]);
    file = fopen(path, "wt");
    if (0 == file) {
      fprintf(stderr, "Unable to open '%s' for writing", path);
      return -2;
    }
    sprintf(body,
            "#include <stdio.h>\n\nvoid MyGeneratedFunction(){ printf(\"Hello "
            "world, using keyword setting %s\\n\"); }\n",
            argv[2]);
    fwrite(body, 1, strlen(body), file);
    fclose(file);
    fprintf(stdout, "Generated source file written to '%s'\n", path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a6 <main+0x46>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <main+0x134>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe59(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x218(%rbp)
xor    %eax,%eax
cmp    -0x218(%rbp),%rax
jne    1214 <main+0xb4>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1294 <main+0x134>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe11(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x220(%rbp),%rdi
mov    %eax,%edx
mov    -0x218(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
cmp    $0x2,%edi
jg     11a0 <main+0x30>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1237 <main+0xc7>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1218 <main+0xa8>
mov    %rax,%r14
mov    0x10(%rbx),%rdx
lea    0xe64(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
lea    0xe8f(%rip),%rsi
mov    0x2dc2(%rip),%rax
jmp    122b <main+0xbb>
mov    $0xfffffffe,%ebx
lea    0xdf4(%rip),%rsi
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Not enough arguments\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [32 x i8] c"Unable to open '%s' for writing\00"
@.str.4 = [102 x i8] c"#include <stdio.h>\0A\0Avoid MyGeneratedFunction(){ printf(\22Hello world, using keyword setting %s\\n\22); }\0A\00"
@stdout = global i32 0
@.str.5 = [39 x i8] c"Generated source file written to '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
14: ; preds = %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %26)
store i32 -2, i32* %3
br label %44
28: ; preds = %14
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = load i32*, i32** %8
%38 = call i32 @fwrite(i8* %34, i32 1, i32 %36, i32* %37)
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* @stdout
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %42)
store i32 0, i32* %3
br label %44
44: ; preds = %28, %24, %11
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Not enough arguments\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [32 x i8] c"Unable to open '%s' for writing\00"
@.str.4 = [102 x i8] c"#include <stdio.h>\0A\0Avoid MyGeneratedFunction(){ printf(\22Hello world, using keyword setting %s\\n\22); }\0A\00"
@stdout = global i32 0
@.str.5 = [39 x i8] c"Generated source file written to '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %30
9: ; preds = %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i8* @strcpy(i8* %10, i8* dereferenceable(1) %13)
%15 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %24, label %17
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = call i32 @strlen(i8* %11)
%22 = call i32 @fwrite(i8* %11, i32 1, i32 %21, i32* %15)
%23 = call i32 @fclose(i32* %15)
br label %24
24: ; preds = %9, %17
%25 = phi i32* [ @stdout, %17 ], [ @stderr, %9 ]
%26 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), %17 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), %9 ]
%27 = phi i32 [ 0, %17 ], [ -2, %9 ]
%28 = load i32, i32* %25
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* %26, i8* %10)
br label %30
30: ; preds = %24, %6
%31 = phi i32 [ -1, %6 ], [ %27, %24 ]
ret i32 %31
}