#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  char *line = NULL;
  char c;
  int no, i;
  size_t len = 0;
  pid_t x;
  printf("Enter the no of commands\n");
  scanf("%d", &no);
  scanf("%c", &c);
  x = fork();
  if (!x) {
    printf("Enter the commands\n");
    for (i = 0; i <= no; i++) {
      getline(&line, &len, stdin);
      system(line);
      free(line);
      line = NULL;
      len = 0;
    }
  } else {
    wait(&x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe69(%rip),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    123d <main+0xcd>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1238 <main+0xc8>
mov    0x2def(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getline@plt>
mov    -0x10(%rbp),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e6 <main+0x76>
jmp    1246 <main+0xd6>
lea    -0x2c(%rbp),%rdi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xe61(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe51(%rip),%rdi
lea    0xb(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,0x1c(%rsp)
test   %eax,%eax
je     11d9 <main+0x69>
lea    0x1c(%rsp),%rdi
call   1080 <wait@plt>
jmp    124d <main+0xdd>
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
js     124d <main+0xdd>
mov    $0xffffffff,%ebp
mov    0x2df0(%rip),%r15
lea    0x10(%rsp),%r14
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <getline@plt>
mov    0x10(%rsp),%rdi
call   1050 <system@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     1210 <main+0xa0>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter the no of commands\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [20 x i8] c"Enter the commands\0A\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i64 0, i64* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = call i32 (...) @fork()
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %31, label %14
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %16
16: ; preds = %27, %14
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32, i32* @stdin
%22 = call i32 @getline(i8** %2, i64* %6, i32 %21)
%23 = load i8*, i8** %2
%24 = call i32 @system(i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
store i8* null, i8** %2
store i64 0, i64* %6
br label %27
27: ; preds = %20
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %16
30: ; preds = %16
br label %33
31: ; preds = %0
%32 = call i32 @wait(i32* %7)
br label %33
33: ; preds = %31, %30
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%c\00"
@stdin = global i32 0
@str = [25 x i8] c"Enter the no of commands\00"
@str.4 = [19 x i8] c"Enter the commands\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%7 = bitcast i32* %3 to i8*
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = bitcast i32* %5 to i8*
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%13 = call i32 (...) @fork()
store i32 %13, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %15, %19
%20 = phi i32 [ %27, %19 ], [ 0, %15 ]
%21 = load i32, i32* @stdin
%22 = call i32 @getline(i8** %1, i64* %4, i32 %21)
%23 = load i8*, i8** %1
%24 = call i32 @system(i8* %23)
%25 = load i8*, i8** %1
%26 = call i32 @free(i8* %25)
store i8* null, i8** %1
store i64 0, i64* %4
%27 = add nuw nsw i32 %20, 1
%28 = load i32, i32* %3
%29 = icmp slt i32 %20, %28
br i1 %29, label %19, label %32
30: ; preds = %0
%31 = call i32 @wait(i32* %5)
br label %32
32: ; preds = %19, %15, %30
ret i32 0
}