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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sprintf(char *, char *, char *, ...);
int strlen(char *);
int test_file(char *f_name, char *ex_lang, char *f_output) {
  char filepath[(strlen(ex_lang) + strlen(" ./") + strlen(f_name)) *
                sizeof(char)];
  sprintf(filepath, "%s ./%s", ex_lang, f_name);
  FILE *fp = popen(filepath, "r");
  if (fp == NULL) {
    printf("\nFailed to run %s.", f_name);
    return (-1);
  }
  while (fgets(filepath, (int)sizeof(filepath) - 1, fp) != NULL) {
    if (sprintf(f_output + strlen(f_output), "%s", filepath) < 0) {
      printf("\nFailed to write to output string.");
      return (-1);
    }
  }
  pclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x58(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x48(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1229 <test_file+0xc9>
mov    -0x10(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12c1 <test_file+0x161>
jmp    122e <test_file+0xce>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
sub    $0x1,%esi
mov    -0x38(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12aa <test_file+0x14a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%rdx
cltq
add    %rax,%rdi
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
cmp    $0x0,%rax
jge    12a5 <test_file+0x145>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12c1 <test_file+0x161>
jmp    122e <test_file+0xce>
mov    -0x38(%rbp),%rdi
call   1050 <pclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,-0x30(%rbp)
mov    %rdi,%r13
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0xe77(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
add    %ebx,%r12d
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
add    %r12d,%r14d
mov    %r13,%r12
movslq %r14d,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
mov    -0x30(%rbp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1248 <test_file+0xe8>
mov    %rax,%r13
add    $0xffffffff,%r14d
lea    0xe16(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1260 <test_file+0x100>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
test   %rax,%rax
jns    1200 <test_file+0xa0>
lea    0xde7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    126a <test_file+0x10a>
lea    0xdbf(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    126a <test_file+0x10a>
mov    %r13,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" ./\00"
@.str.1 = [8 x i8] c"%s ./%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"\0AFailed to run %s.\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [35 x i8] c"\0AFailed to write to output string.\00"
define i32 @test_file(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %13, %14
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = call i64 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
%26 = call i32* @popen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %3
%30 = load i8*, i8** %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %30)
store i32 -1, i32* %4
store i32 1, i32* %11
br label %53
32: ; preds = %3
br label %33
33: ; preds = %49, %32
%34 = trunc i64 %20 to i32
%35 = sub nsw i32 %34, 1
%36 = load i32*, i32** %10
%37 = call i32* @fgets(i8* %22, i32 %35, i32* %36)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %50
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = load i8*, i8** %7
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = call i64 (i8*, i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %11
br label %53
49: ; preds = %39
br label %33
50: ; preds = %33
%51 = load i32*, i32** %10
%52 = call i32 @pclose(i32* %51)
store i32 0, i32* %4
store i32 1, i32* %11
br label %53
53: ; preds = %50, %47, %29
%54 = load i8*, i8** %8
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [4 x i8] c" ./\00"
@.str.1 = [8 x i8] c"%s ./%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"\0AFailed to run %s.\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [35 x i8] c"\0AFailed to write to output string.\00"
define i32 @test_file(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = add nsw i32 %5, %4
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %6, %7
%9 = sext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = call i64 (i8*, i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
%12 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = add nsw i32 %8, -1
br label %18
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %31
18: ; preds = %14, %21
%19 = call i32* @fgets(i8* %10, i32 %15, i32* %12)
%20 = icmp eq i32* %19, null
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = call i32 @strlen(i8* %2)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %2, i64 %23
%25 = call i64 (i8*, i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %18
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %31
29: ; preds = %18
%30 = call i32 @pclose(i32* %12)
br label %31
31: ; preds = %29, %27, %16
%32 = phi i32 [ -1, %16 ], [ -1, %27 ], [ 0, %29 ]
ret i32 %32
}