#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int sum_length(int, char **);
int system(char *);
int bc(int argc, char **argv) {
  char echo[] = "echo ";
  char bc_calc[] = "|bc";
  char *expr =
      (char *)malloc(sizeof(char) * (sum_length(argc - 1, argv + 1) + 1 +
                                     strlen(echo) + strlen(bc_calc)));
  strcpy(expr, echo);
  for (int i = 1; i < argc; ++i)
    strcat(expr, argv[i]);
  strcat(expr, bc_calc);
  printf("expr=%s\n", expr);
  return system(expr);
}


x86 assembly (clang, -O0):
<bc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe7b(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xe75(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xe6d(%rip),%eax
mov    %eax,-0x1a(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <sum_length@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x16(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
lea    -0x1a(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    122c <bc+0xbc>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <strcat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fd <bc+0x8d>
mov    -0x28(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rsi
lea    0xdc6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <system@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
movw   $0x20,0x14(%rsp)
movl   $0x6f686365,0x10(%rsp)
6f
movl   $0x63627c,0xc(%rsp)
lea    -0x1(%r14),%edi
add    $0x8,%rsi
call   1080 <sum_length@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
add    %ebp,%ebx
lea    0xc(%rsp),%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%r14d
jl     1205 <bc+0x95>
mov    %r14d,%ebp
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rsi
mov    %r13,%rdi
call   1090 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <bc+0x80>
lea    0xc(%rsp),%rsi
mov    %r13,%rdi
call   1090 <strcat@plt>
lea    0xded(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
mov    %r13,%rdi
call   1050 <system@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.bc.echo = [6 x i8] c"echo \00"
@__const.bc.bc_calc = [4 x i8] c"|bc\00"
@.str = [9 x i8] c"expr=%s\0A\00"
define i32 @bc(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [6 x i8]
%6 = alloca [4 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = bitcast [6 x i8]* %5 to i8*
%10 = bitcast [4 x i8]* %6 to i8*
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = call i32 @sum_length(i32 %12, i8** %14)
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = sext i32 %22 to i64
%24 = mul i64 1, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%30 = call i32 @strcpy(i8* %28, i8* %29)
store i32 1, i32* %8
br label %31
31: ; preds = %43, %2
%32 = load i32, i32* %8
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i8*, i8** %7
%37 = load i8**, i8*** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @strcat(i8* %36, i8* %41)
br label %43
43: ; preds = %35
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %31
46: ; preds = %31
%47 = load i8*, i8** %7
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %7
%51 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %7
%53 = call i32 @system(i8* %52)
ret i32 %53
}

LLVM IR (-O2):
@__const.bc.echo = [6 x i8] c"echo \00"
@.str = [9 x i8] c"expr=%s\0A\00"
define i32 @bc(i32 %0, i8** %1) {
%3 = alloca [6 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 6513276, i32* %4
%7 = add nsw i32 %0, -1
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = tail call i32 @sum_length(i32 %7, i8** %8)
%10 = add nsw i32 %9, 1
%11 = call i32 @strlen(i8* %5)
%12 = add nsw i32 %10, %11
%13 = call i32 @strlen(i8* %6)
%14 = add nsw i32 %12, %13
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @strcpy(i8* %16, i8* %5)
%18 = icmp sgt i32 %0, 1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = zext i32 %0 to i64
br label %25
21: ; preds = %25, %2
%22 = call i32 @strcat(i8* %16, i8* %6)
%23 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16)
%24 = call i32 @system(i8* %16)
ret i32 %24
25: ; preds = %19, %25
%26 = phi i64 [ 1, %19 ], [ %30, %25 ]
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strcat(i8* %16, i8* %28)
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, %20
br i1 %31, label %21, label %25
}