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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: ./solution someprog param\n");
    exit(1);
  }
  FILE *fd;
  char output[4096];
  int cnt = 0;
  char cmd[1024];
  strcpy(cmd, argv[1]);
  strcat(cmd, " ");
  strcat(cmd, argv[2]);
  fd = popen(cmd, "r");
  if (fd == NULL) {
    printf("Failed to exec\n");
    exit(1);
  }
  while (fgets(output, sizeof(output) - 1, fd) != NULL) {
    int i = 0;
    for (i = 0; i < strlen(output); i++) {
      if (output[i] == '0') {
        cnt++;
      }
    }
  }
  pclose(fd);
  printf("%d\n", cnt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1024(%rbp)
lea    -0x1430(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x1430(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x1430(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcat@plt>
lea    -0x1430(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123a <main+0xba>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    123f <main+0xbf>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xfff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12df <main+0x15f>
movl   $0x0,-0x1434(%rbp)
movl   $0x0,-0x1434(%rbp)
mov    -0x1434(%rbp),%eax
mov    %eax,-0x1438(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1438(%rbp),%eax
cmp    %ecx,%eax
jge    12da <main+0x15a>
movslq -0x1434(%rbp),%rax
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jne    12c1 <main+0x141>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
jmp    12c6 <main+0x146>
mov    -0x1434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1434(%rbp)
jmp    1272 <main+0xf2>
jmp    123f <main+0xbf>
mov    -0x18(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x1024(%rbp),%esi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x1440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1408,%rsp
cmp    $0x2,%edi
jle    129f <main+0x10f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe40(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
lea    0xe27(%rip),%rsi
mov    %r14,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     12a8 <main+0x118>
mov    %rax,%r14
lea    0x400(%rsp),%rdi
mov    $0xfff,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1275 <main+0xe5>
lea    0x400(%rsp),%r15
jmp    1235 <main+0xa5>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1275 <main+0xe5>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1220 <main+0x90>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmpb   $0x30,0x400(%rsp,%rbx,1)
30
sete   %al
add    %eax,%r12d
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1250 <main+0xc0>
jmp    1220 <main+0x90>
mov    %r14,%rdi
call   1070 <pclose@plt>
lea    0xd80(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd71(%rip),%rdi
jmp    12af <main+0x11f>
lea    0xd59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Usage: ./solution someprog param\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"Failed to exec\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 0, i32* %8
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %17, i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @strcat(i8* %24, i8* %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = call i32* @popen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %16
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %16
br label %37
37: ; preds = %62, %36
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32* @fgets(i8* %38, i32 4095, i32* %39)
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %63
42: ; preds = %37
store i32 0, i32* %10
store i32 0, i32* %10
br label %43
43: ; preds = %59, %42
%44 = load i32, i32* %10
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = icmp slt i32 %44, %46
br i1 %47, label %48, label %62
48: ; preds = %43
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 48
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %58
58: ; preds = %55, %48
br label %59
59: ; preds = %58
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %43
62: ; preds = %43
br label %37
63: ; preds = %37
%64 = load i32*, i32** %6
%65 = call i32 @pclose(i32* %64)
%66 = load i32, i32* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [15 x i8] c"Failed to exec\00"
@str.5 = [33 x i8] c"Usage: ./solution someprog param\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [1024 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strcpy(i8* %11, i8* %13)
%15 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @strcat(i8* %11, i8* %17)
%19 = call i32* @popen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %9
%22 = call i32* @fgets(i8* %10, i32 4095, i32* %19)
%23 = icmp eq i32* %22, null
br i1 %23, label %47, label %31
24: ; preds = %9
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %35, %31
%28 = phi i32 [ %32, %31 ], [ %42, %35 ]
%29 = call i32* @fgets(i8* %10, i32 4095, i32* %19)
%30 = icmp eq i32* %29, null
br i1 %30, label %47, label %31
31: ; preds = %21, %27
%32 = phi i32 [ %28, %27 ], [ 0, %21 ]
%33 = call i32 @strlen(i8* %10)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %27
35: ; preds = %31, %35
%36 = phi i64 [ %43, %35 ], [ 0, %31 ]
%37 = phi i32 [ %42, %35 ], [ %32, %31 ]
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %36
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 48
%41 = zext i1 %40 to i32
%42 = add nsw i32 %37, %41
%43 = add nuw nsw i64 %36, 1
%44 = call i32 @strlen(i8* %10)
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %35, label %27
47: ; preds = %27, %21
%48 = phi i32 [ 0, %21 ], [ %28, %27 ]
%49 = call i32 @pclose(i32* %19)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %48)
ret i32 0
}