#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*/ config_file_name;
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*/ printf(char *, ...);
int /*<<< orphan*/ restart_apache();
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ validate_host_name(char const *);
void create_proxy(const char *host, int port) {
  char config_file_name[1024];
  FILE *config_file = NULL;
  if (!validate_host_name(host)) {
    printf("Invalid host name.\n");
    return;
  }
  snprintf(config_file_name, sizeof(config_file_name),
           "/etc/apache2/other/localghost.%s.conf", host);
  config_file = fopen(config_file_name, "w");
  if (!config_file) {
    printf("Could not open %s\n", config_file_name);
    return;
  }
  fprintf(config_file, "<VirtualHost 127.0.0.1:80>\n");
  fprintf(config_file, "\tServerName %s\n", host);
  fprintf(config_file, "\tProxyPass / http://localhost:%i/\n", port);
  fprintf(config_file, "\tProxyPassReverse http://localhost:%i/ /\n", port);
  fprintf(config_file, "\tProxyPreserveHost On\n");
  fprintf(config_file, "</VirtualHost>\n");
  fclose(config_file);
  restart_apache();
}


x86 assembly (clang, -O0):
<create_proxy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <validate_host_name@plt>
cmp    $0x0,%eax
jne    11b2 <create_proxy+0x42>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ab <create_proxy+0x13b>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xe4b(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1210 <create_proxy+0xa0>
lea    -0x410(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ab <create_proxy+0x13b>
mov    -0x418(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1080 <restart_apache@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_proxy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
call   1070 <validate_host_name@plt>
test   %eax,%eax
je     127b <create_proxy+0xeb>
lea    0xe4b(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rcx
call   1060 <snprintf@plt>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1292 <create_proxy+0x102>
mov    %rax,%rbx
lea    0xe51(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe75(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0xe73(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1090 <restart_apache@plt>
jmp    12a3 <create_proxy+0x113>
lea    0xe59(%rip),%rdi
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
lea    0xd8f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Invalid host name.\0A\00"
@.str.1 = [38 x i8] c"/etc/apache2/other/localghost.%s.conf\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [19 x i8] c"Could not open %s\0A\00"
@.str.4 = [28 x i8] c"<VirtualHost 127.0.0.1:80>\0A\00"
@.str.5 = [16 x i8] c"\09ServerName %s\0A\00"
@.str.6 = [35 x i8] c"\09ProxyPass / http://localhost:%i/\0A\00"
@.str.7 = [42 x i8] c"\09ProxyPassReverse http://localhost:%i/ /\0A\00"
@.str.8 = [23 x i8] c"\09ProxyPreserveHost On\0A\00"
@.str.9 = [16 x i8] c"</VirtualHost>\0A\00"
define void @create_proxy(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32* null, i32** %6
%7 = load i8*, i8** %3
%8 = call i32 @validate_host_name(i8* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %42
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %12
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %42
23: ; preds = %12
%24 = load i32*, i32** %6
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32*, i32** %6
%27 = load i8*, i8** %3
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = load i32*, i32** %6
%30 = load i32, i32* %4
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = load i32*, i32** %6
%33 = load i32, i32* %4
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%35 = load i32*, i32** %6
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%37 = load i32*, i32** %6
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = call i32 (...) @restart_apache()
br label %42
42: ; preds = %23, %20, %10
ret void
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"/etc/apache2/other/localghost.%s.conf\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [19 x i8] c"Could not open %s\0A\00"
@.str.4 = [28 x i8] c"<VirtualHost 127.0.0.1:80>\0A\00"
@.str.5 = [16 x i8] c"\09ServerName %s\0A\00"
@.str.6 = [35 x i8] c"\09ProxyPass / http://localhost:%i/\0A\00"
@.str.7 = [42 x i8] c"\09ProxyPassReverse http://localhost:%i/ /\0A\00"
@.str.8 = [23 x i8] c"\09ProxyPreserveHost On\0A\00"
@.str.9 = [16 x i8] c"</VirtualHost>\0A\00"
@str = [19 x i8] c"Invalid host name.\00"
define void @create_proxy(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @validate_host_name(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %24
9: ; preds = %2
%10 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %24
15: ; preds = %9
%16 = call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 27, i64 1, i32* %11)
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %1)
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %1)
%20 = call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i64 22, i64 1, i32* %11)
%21 = call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i64 15, i64 1, i32* %11)
%22 = call i32 @fclose(i32* %11)
%23 = call i32 (...) @restart_apache()
br label %24
24: ; preds = %15, %13, %7
ret void
}