#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*/ free(char *);
char *gmk_expand(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, char *,
                           char *);
size_t strlen(char const *);
char *run_cmd(char const *cmd, char *filename) {
  size_t len1, len2;
  char *str, *result;
  len1 = strlen(cmd);
  len2 = strlen(filename);
  str = malloc(8 + len1 + 1 + len2 + 2 + len2 + 7 + len2 + 15);
  if (!str)
    return NULL;
  sprintf(str, "$(shell %s %s >%s.out 2>%s.err;echo $$?)", cmd, filename,
          filename, filename);
  result = gmk_expand(str);
  free(str);
  return result;
}


x86 assembly (clang, -O0):
<run_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
add    $0x1,%rax
add    -0x28(%rbp),%rax
add    $0x2,%rax
add    -0x28(%rbp),%rax
add    $0x7,%rax
add    -0x28(%rbp),%rax
add    $0xf,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c1 <run_cmd+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11ff <run_cmd+0xaf>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe24(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <gmk_expand@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_cmd>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rax,2),%eax
lea    (%rbx,%rax,1),%edi
add    $0x21,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b4 <run_cmd+0x64>
mov    %rax,%rbx
lea    0xe78(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r15,%r8
mov    %r15,%r9
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <gmk_expand@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
jmp    11b6 <run_cmd+0x66>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"$(shell %s %s >%s.out 2>%s.err;echo $$?)\00"
define i8* @run_cmd(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i64, i64* %6
%15 = add i64 8, %14
%16 = add i64 %15, 1
%17 = load i64, i64* %7
%18 = add i64 %16, %17
%19 = add i64 %18, 2
%20 = load i64, i64* %7
%21 = add i64 %19, %20
%22 = add i64 %21, 7
%23 = load i64, i64* %7
%24 = add i64 %22, %23
%25 = add i64 %24, 15
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %2
store i8* null, i8** %3
br label %43
31: ; preds = %2
%32 = load i8*, i8** %8
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = load i8*, i8** %5
%36 = load i8*, i8** %5
%37 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34, i8* %35, i8* %36)
%38 = load i8*, i8** %8
%39 = call i8* @gmk_expand(i8* %38)
store i8* %39, i8** %9
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %9
store i8* %42, i8** %3
br label %43
43: ; preds = %31, %30
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [41 x i8] c"$(shell %s %s >%s.out 2>%s.err;echo $$?)\00"
define i8* @run_cmd(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = mul i64 %4, 3
%6 = add i64 %3, 18
%7 = add i64 %6, %5
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 15
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = tail call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %1, i8* %1)
%14 = tail call i8* @gmk_expand(i8* %10)
%15 = tail call i32 @free(i8* %10)
br label %16
16: ; preds = %2, %12
%17 = phi i8* [ %14, %12 ], [ null, %2 ]
ret i8* %17
}