#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 */

/* Variables and functions */
int /*<<< orphan*/ add_argument(char *);
int /*<<< orphan*/ build_arglist(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memory();
char *pathmod(char *, char *, char *, int);
int /*<<< orphan*/ redirect_in(char *);
int /*<<< orphan*/ redirect_out(char *);
int /*<<< orphan*/ run_command();
char *strdup(char *);
void convert_c_to_s(char *path) {
  char *tmp;
  build_arglist("/usr/lib/cc");
  redirect_in(path);
  tmp = strdup(pathmod(path, ".%", ".@", 0));
  if (tmp == NULL)
    memory();
  redirect_out(tmp);
  run_command();
  build_arglist("/usr/lib/copt");
  add_argument("/usr/lib/cc-copt");
  redirect_in(tmp);
  redirect_out(pathmod(path, ".%", ".s", 2));
  run_command();
  free(tmp);
}


x86 assembly (clang, -O0):
<convert_c_to_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
call   1090 <build_arglist@plt>
mov    -0x8(%rbp),%rdi
call   1080 <redirect_in@plt>
mov    -0x8(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    0xe4c(%rip),%rdx
xor    %ecx,%ecx
call   10b0 <pathmod@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e8 <convert_c_to_s+0x58>
mov    $0x0,%al
call   1060 <memory@plt>
mov    -0x10(%rbp),%rdi
call   1040 <redirect_out@plt>
mov    $0x0,%al
call   1070 <run_command@plt>
lea    0xe13(%rip),%rdi
call   1090 <build_arglist@plt>
lea    0xe15(%rip),%rdi
call   1050 <add_argument@plt>
mov    -0x10(%rbp),%rdi
call   1080 <redirect_in@plt>
mov    -0x8(%rbp),%rdi
lea    0xde8(%rip),%rsi
lea    0xe06(%rip),%rdx
mov    $0x2,%ecx
call   10b0 <pathmod@plt>
mov    %rax,%rdi
call   1040 <redirect_out@plt>
mov    $0x0,%al
call   1070 <run_command@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_c_to_s>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe62(%rip),%rdi
call   1090 <build_arglist@plt>
mov    %r14,%rdi
call   1080 <redirect_in@plt>
lea    0xe5a(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    %r14,%rdi
xor    %ecx,%ecx
call   10b0 <pathmod@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11da <convert_c_to_s+0x4a>
xor    %eax,%eax
call   1060 <memory@plt>
mov    %rbx,%rdi
call   1040 <redirect_out@plt>
xor    %eax,%eax
call   1070 <run_command@plt>
lea    0xe22(%rip),%rdi
call   1090 <build_arglist@plt>
lea    0xe24(%rip),%rdi
call   1050 <add_argument@plt>
mov    %rbx,%rdi
call   1080 <redirect_in@plt>
lea    0xdfc(%rip),%rsi
lea    0xe1a(%rip),%rdx
mov    %r14,%rdi
mov    $0x2,%ecx
call   10b0 <pathmod@plt>
mov    %rax,%rdi
call   1040 <redirect_out@plt>
xor    %eax,%eax
call   1070 <run_command@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/usr/lib/cc\00"
@.str.1 = [3 x i8] c".%\00"
@.str.2 = [3 x i8] c".@\00"
@.str.3 = [14 x i8] c"/usr/lib/copt\00"
@.str.4 = [17 x i8] c"/usr/lib/cc-copt\00"
@.str.5 = [3 x i8] c".s\00"
define void @convert_c_to_s(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i32 @build_arglist(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %2
%6 = call i32 @redirect_in(i8* %5)
%7 = load i8*, i8** %2
%8 = call i8* @pathmod(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 (...) @memory()
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %3
%16 = call i32 @redirect_out(i8* %15)
%17 = call i32 (...) @run_command()
%18 = call i32 @build_arglist(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @add_argument(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = call i32 @redirect_in(i8* %20)
%22 = load i8*, i8** %2
%23 = call i8* @pathmod(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%24 = call i32 @redirect_out(i8* %23)
%25 = call i32 (...) @run_command()
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/usr/lib/cc\00"
@.str.1 = [3 x i8] c".%\00"
@.str.2 = [3 x i8] c".@\00"
@.str.3 = [14 x i8] c"/usr/lib/copt\00"
@.str.4 = [17 x i8] c"/usr/lib/cc-copt\00"
@.str.5 = [3 x i8] c".s\00"
define void @convert_c_to_s(i8* %0) {
%2 = tail call i32 @build_arglist(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @redirect_in(i8* %0)
%4 = tail call i8* @pathmod(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
%5 = tail call i8* @strdup(i8* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (...) @memory()
br label %9
9: ; preds = %7, %1
%10 = tail call i32 @redirect_out(i8* %5)
%11 = tail call i32 (...) @run_command()
%12 = tail call i32 @build_arglist(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @add_argument(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @redirect_in(i8* %5)
%15 = tail call i8* @pathmod(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%16 = tail call i32 @redirect_out(i8* %15)
%17 = tail call i32 (...) @run_command()
%18 = tail call i32 @free(i8* %5)
ret void
}