#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *get_command_from_argv(int optind, int argc, char **argv, char *optarg,
                            char *command) {
  int index = 0;
  strcpy(command, optarg);
  strcat(command, " ");
  for (index = optind; index < argc; index++) {
    strcat(command, argv[index]);
    strcat(command, " ");
  }
  if (strlen(command) == 1) {
    fprintf(stderr, "Error: command missing \n");
    print_usage();
    exit(1);
  } else if (strlen(command) > 4096) {
    fprintf(stderr, "Error: Too long command \n");
    print_usage();
    exit(1);
  }
  return command;
}


x86 assembly (clang, -O0):
<get_command_from_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <get_command_from_argv+0x83>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <get_command_from_argv+0x44>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    121b <get_command_from_argv+0xbb>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1080 <print_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1000,%eax
jle    1255 <get_command_from_argv+0xf5>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1080 <print_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    125a <get_command_from_argv+0xfa>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_command_from_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%r12d
mov    %r8,%rdi
mov    %rcx,%rsi
call   1030 <strcpy@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
cmp    %r14d,%r12d
jge    11d1 <get_command_from_argv+0x71>
movslq %r12d,%rax
lea    (%r15,%rax,8),%r13
sub    %r12d,%r14d
xor    %ebp,%ebp
lea    0xe57(%rip),%r15
nopl   0x0(%rax)
mov    0x0(%r13,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    11b0 <get_command_from_argv+0x50>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11ff <get_command_from_argv+0x9f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1001,%eax
jge    1211 <get_command_from_argv+0xb1>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
jmp    1221 <get_command_from_argv+0xc1>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1080 <print_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error: command missing \0A\00"
@.str.2 = [26 x i8] c"Error: Too long command \0A\00"
define i8* @get_command_from_argv(i32 %0, i32 %1, i8** %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
%12 = load i8*, i8** %10
%13 = load i8*, i8** %9
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %10
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %6
store i32 %17, i32* %11
br label %18
18: ; preds = %32, %5
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = load i8**, i8*** %8
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strcat(i8* %23, i8* %28)
%30 = load i8*, i8** %10
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %22
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %18
35: ; preds = %18
%36 = load i8*, i8** %10
%37 = call i32 @strlen(i8* %36)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 (...) @print_usage()
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
%45 = load i8*, i8** %10
%46 = call i32 @strlen(i8* %45)
%47 = icmp sgt i32 %46, 4096
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 (...) @print_usage()
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
br label %54
54: ; preds = %53
%55 = load i8*, i8** %10
ret i8* %55
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error: command missing \0A\00"
@.str.2 = [26 x i8] c"Error: Too long command \0A\00"
define i8* @get_command_from_argv(i32 %0, i32 %1, i8** nocapture %2, i8* %3, i8* returned %4) {
%6 = tail call i32 @strcpy(i8* %4, i8* %3)
%7 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp slt i32 %0, %1
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = sext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %17, %11 ]
%13 = getelementptr inbounds i8*, i8** %2, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strcat(i8* %4, i8* %14)
%16 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = add nsw i64 %12, 1
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %11
20: ; preds = %11, %5
%21 = tail call i32 @strlen(i8* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 (...) @print_usage()
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = tail call i32 @strlen(i8* %4)
%30 = icmp sgt i32 %29, 4096
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 (...) @print_usage()
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %28
ret i8* %4
}