#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*/ strncpy(char *, char *, int);
int system(char *);
int c_system(int count, char command[]) {
  int i;
  char buffer[2000];
  if (2000 - 1 > count)
    return -1;
  strncpy(buffer, command, count);
  buffer[count] = 0;
  buffer[count - 1] = 0;
  return system(buffer);
}


x86 assembly (clang, -O0):
<c_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x7cf,%eax
cmp    -0x8(%rbp),%eax
jle    114c <c_system+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <c_system+0x6a>
lea    -0x7f0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x7f0(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x7f0(%rbp,%rax,1)
lea    -0x7f0(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_system>:
mov    $0xffffffff,%eax
cmp    $0x7cf,%edi
jl     1165 <c_system+0x45>
push   %r14
push   %rbx
sub    $0x7d8,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
add    $0xffffffff,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
call   1040 <system@plt>
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @c_system(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [2000 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 1999, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %25
11: ; preds = %2
%12 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = load i32, i32* %4
%15 = call i32 @strncpy(i8* %12, i8* %13, i32 %14)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%24 = call i32 @system(i8* %23)
store i32 %24, i32* %3
br label %25
25: ; preds = %11, %10
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @c_system(i32 %0, i8* %1) {
%3 = alloca [2000 x i8]
%4 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 1999
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = call i32 @strncpy(i8* %4, i8* %1, i32 %0)
%8 = zext i32 %0 to i64
%9 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %8
store i8 0, i8* %9
%10 = add nsw i32 %0, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @system(i8* %4)
br label %14
14: ; preds = %2, %6
%15 = phi i32 [ %13, %6 ], [ -1, %2 ]
ret i32 %15
}