#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 EXIT_FAILURE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char cmd[100] = {0};
  if (argc < 3) {
    fprintf(stdout,
            "please intput cmd and argv, such as ./linux_cmd echo \"12312\"\n");
    return EXIT_FAILURE;
  }
  fprintf(stdout, "下面的输出是调用系统命令后的输出\n");
  sprintf(cmd, "%s %s", argv[1], argv[2]);
  system(cmd);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1199 <main+0x59>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <main+0x9e>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xea7(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <system@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    %edi,%eax
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    0x2e72(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x2,%eax
jg     1184 <main+0x54>
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
jmp    11ba <main+0x8a>
mov    %rsi,%rbx
lea    0xeb0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xece(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [62 x i8] c"please intput cmd and argv, such as ./linux_cmd echo \2212312\22\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"\E4\B8\8B\E9\9D\A2\E7\9A\84\E8\BE\93\E5\87\BA\E6\98\AF\E8\B0\83\E7\94\A8\E7\B3\BB\E7\BB\9F\E5\91\BD\E4\BB\A4\E5\90\8E\E7\9A\84\E8\BE\93\E5\87\BA\0A\00"
@.str.2 = [6 x i8] c"%s %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [100 x i8]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %27
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%26 = call i32 @system(i8* %25)
store i32 1, i32* %3
br label %27
27: ; preds = %14, %10
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [62 x i8] c"please intput cmd and argv, such as ./linux_cmd echo \2212312\22\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"\E4\B8\8B\E9\9D\A2\E7\9A\84\E8\BE\93\E5\87\BA\E6\98\AF\E8\B0\83\E7\94\A8\E7\B3\BB\E7\BB\9F\E5\91\BD\E4\BB\A4\E5\90\8E\E7\9A\84\E8\BE\93\E5\87\BA\0A\00"
@.str.2 = [6 x i8] c"%s %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
%6 = load i32, i32* @stdout
br i1 %5, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
br label %18
10: ; preds = %2
%11 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %15)
%17 = call i32 @system(i8* %4)
br label %18
18: ; preds = %10, %7
%19 = phi i32 [ %9, %7 ], [ 1, %10 ]
ret i32 %19
}