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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
size_t strcspn(char *, char *);
int runprogram(char *progname, char *tmpname) {
  FILE *p;
  char cmdline[BUFSIZ];
  char outbuff[BUFSIZ];
  progname[strcspn(progname, "\n")] = 0;
  sprintf(cmdline, "%s %s", progname, tmpname);
  if ((p = popen(cmdline, "r")) == NULL) {
    fprintf(stderr, "Could not open pipe to %s\n", cmdline);
    exit(-1);
  }
  while (fgets(outbuff, sizeof(outbuff), p) != NULL) {
    fprintf(stdout, "%s", outbuff);
  }
  pclose(p);
  return (0);
}


x86 assembly (clang, -O0):
<runprogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1040 <strcspn@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdfc(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    124a <runprogram+0xda>
mov    -0x38(%rbp),%rdx
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    124f <runprogram+0xdf>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     128a <runprogram+0x11a>
mov    -0x48(%rbp),%rdx
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
call   1060 <fprintf@plt>
jmp    124f <runprogram+0xdf>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runprogram>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e4d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe72(%rip),%rsi
call   1040 <strcspn@plt>
movb   $0x0,0x0(%r13,%rax,1)
lea    0xe3f(%rip),%rsi
mov    %r15,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
call   1080 <sprintf@plt>
lea    0xe30(%rip),%rsi
mov    %r15,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     124b <runprogram+0xdb>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1232 <runprogram+0xc2>
mov    0x2dd0(%rip),%r13
lea    0xdfc(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1210 <runprogram+0xa0>
mov    %r12,%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"Could not open pipe to %s\0A\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @runprogram(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
store i64 %14, i64* %8
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strcspn(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
%23 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %5
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %2
br label %30
30: ; preds = %35, %29
%31 = trunc i64 %14 to i32
%32 = load i32*, i32** %5
%33 = call i32* @fgets(i8* %15, i32 %31, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @stdout
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %30
38: ; preds = %30
%39 = load i32*, i32** %5
%40 = call i32 @pclose(i32* %39)
%41 = load i8*, i8** %6
ret i32 0
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"Could not open pipe to %s\0A\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @runprogram(i8* %0, i8* %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%10 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i32* @fgets(i8* %6, i32 %3, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %24, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %12, %19
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%22 = call i32* @fgets(i8* %6, i32 %3, i32* %10)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %19
24: ; preds = %19, %12
%25 = call i32 @pclose(i32* %10)
ret i32 0
}