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

/* Variables and functions */
char *cfg_get_vicmd(int *);
char *escape_filename(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ run_vim(char *, int, int);
size_t snprintf(char *, int, char *, char *);
void vim_edit_files(int nfiles, char *files[]) {
  char cmd[4096];
  size_t len;
  int i;
  int bg;
  len = snprintf(cmd, sizeof(cmd), "%s ", cfg_get_vicmd(&bg));
  for (i = 0; i < nfiles && len < sizeof(cmd) - 1; ++i) {
    char *escaped = escape_filename(files[i], 0);
    len += snprintf(cmd + len, sizeof(cmd) - len, "%s ", escaped);
    free(escaped);
  }
  run_vim(cmd, bg, 1);
}


x86 assembly (clang, -O0):
<vim_edit_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1060 <cfg_get_vicmd@plt>
mov    -0x1030(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xe6e(%rip),%rdx
call   1050 <snprintf@plt>
mov    %rax,-0x1018(%rbp)
movl   $0x0,-0x101c(%rbp)
mov    -0x101c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x1031(%rbp)
jge    11d3 <vim_edit_files+0x83>
cmpq   $0xfff,-0x1018(%rbp)
setb   %al
mov    %al,-0x1031(%rbp)
mov    -0x1031(%rbp),%al
test   $0x1,%al
jne    11e6 <vim_edit_files+0x96>
jmp    1260 <vim_edit_files+0x110>
mov    -0x10(%rbp),%rax
movslq -0x101c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
call   1040 <escape_filename@plt>
mov    %rax,-0x1028(%rbp)
lea    -0x1010(%rbp),%rdi
add    -0x1018(%rbp),%rdi
mov    $0x1000,%eax
sub    -0x1018(%rbp),%rax
mov    %eax,%esi
mov    -0x1028(%rbp),%rcx
lea    0xdd3(%rip),%rdx
call   1050 <snprintf@plt>
add    -0x1018(%rbp),%rax
mov    %rax,-0x1018(%rbp)
mov    -0x1028(%rbp),%rdi
call   1030 <free@plt>
mov    -0x101c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x101c(%rbp)
jmp    11a8 <vim_edit_files+0x58>
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%esi
mov    $0x1,%edx
call   1070 <run_vim@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vim_edit_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xc(%rsp),%rdi
call   1060 <cfg_get_vicmd@plt>
lea    0xe89(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
test   %ebp,%ebp
jle    11fd <vim_edit_files+0xad>
mov    %rax,%rbx
cmp    $0xffe,%rax
ja     11fd <vim_edit_files+0xad>
mov    %ebp,%r13d
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    -0x8(%r14,%r15,8),%rdi
xor    %esi,%esi
call   1040 <escape_filename@plt>
mov    %rax,%r12
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x1000,%esi
sub    %ebx,%esi
lea    0xe2b(%rip),%rdx
mov    %rax,%rcx
call   1050 <snprintf@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1030 <free@plt>
cmp    %r13,%r15
jae    11fd <vim_edit_files+0xad>
add    %rbp,%rbx
add    $0x1,%r15
cmp    $0xfff,%rbx
jb     11b0 <vim_edit_files+0x60>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
mov    $0x1,%edx
call   1070 <run_vim@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
define void @vim_edit_files(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [4096 x i8]
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%11 = call i8* @cfg_get_vicmd(i32* %8)
%12 = call i64 @snprintf(i8* %10, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
store i64 %12, i64* %6
store i32 0, i32* %7
br label %13
13: ; preds = %41, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i64, i64* %6
%19 = icmp ult i64 %18, 4095
br label %20
20: ; preds = %17, %13
%21 = phi i1 [ false, %13 ], [ %19, %17 ]
br i1 %21, label %22, label %44
22: ; preds = %20
%23 = load i8**, i8*** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i8* @escape_filename(i8* %27, i32 0)
store i8* %28, i8** %9
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i64, i64* %6
%33 = sub i64 4096, %32
%34 = trunc i64 %33 to i32
%35 = load i8*, i8** %9
%36 = call i64 @snprintf(i8* %31, i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i64, i64* %6
%38 = add i64 %37, %36
store i64 %38, i64* %6
%39 = load i8*, i8** %9
%40 = call i32 @free(i8* %39)
br label %41
41: ; preds = %22
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %13
44: ; preds = %20
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%46 = load i32, i32* %8
%47 = call i32 @run_vim(i8* %45, i32 %46, i32 1)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
define void @vim_edit_files(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i8* @cfg_get_vicmd(i32* %4)
%8 = call i64 @snprintf(i8* %5, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp sgt i32 %0, 0
%10 = icmp ult i64 %8, 4095
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %26, %14 ]
%16 = phi i64 [ %8, %12 ], [ %24, %14 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %15
%18 = load i8*, i8** %17
%19 = call i8* @escape_filename(i8* %18, i32 0)
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %16
%21 = trunc i64 %16 to i32
%22 = sub nuw nsw i32 4096, %21
%23 = call i64 @snprintf(i8* %20, i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%24 = add i64 %23, %16
%25 = call i32 @free(i8* %19)
%26 = add nuw nsw i64 %15, 1
%27 = icmp ult i64 %26, %13
%28 = icmp ult i64 %24, 4095
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %14, label %30
30: ; preds = %14, %2
%31 = load i32, i32* %4
%32 = call i32 @run_vim(i8* %5, i32 %31, i32 1)
ret void
}