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

/* Variables and functions */
int /*<<< orphan*/ read_fw_str(char *, char const *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
void read_vmcmd(char *str, const char *path) {
  char buf[128], tmp[512];
  char *ptr_old, *ptr;
  *str = 0;
  ptr_old = ptr = buf;
  read_fw_str(buf, path, sizeof(buf));
  while ((ptr = strchr(ptr_old, '\n'))) {
    *ptr = 0;
    sprintf(tmp, "\"%s\",", ptr_old);
    strcat(str, tmp);
    ptr_old = ptr + 1;
  }
  sprintf(tmp, "\"%s\"", ptr_old);
  strcat(str, tmp);
}


x86 assembly (clang, -O0):
<read_vmcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rax
mov    %rax,-0x2a0(%rbp)
mov    %rax,-0x298(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read_fw_str@plt>
mov    -0x298(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x2a0(%rbp)
cmp    $0x0,%rax
je     11f1 <read_vmcmd+0xb1>
mov    -0x2a0(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x290(%rbp),%rdi
mov    -0x298(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x290(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x2a0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x298(%rbp)
jmp    1184 <read_vmcmd+0x44>
lea    -0x290(%rbp),%rdi
mov    -0x298(%rbp),%rdx
lea    0xe00(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x290(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_vmcmd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x280,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
movb   $0x0,(%rdi)
mov    %rbx,%rdi
mov    $0x80,%edx
call   1040 <read_fw_str@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c9 <read_vmcmd+0x89>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0xe7b(%rip),%r12
lea    0x80(%rsp),%r13
nopl   (%rax)
movb   $0x0,(%r15)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1190 <read_vmcmd+0x50>
lea    0xe36(%rip),%rsi
lea    0x80(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    $0x280,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\22%s\22,\00"
@.str.1 = [5 x i8] c"\22%s\22\00"
define void @read_vmcmd(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
store i8 0, i8* %9
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8* %10, i8** %8
store i8* %10, i8** %7
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @read_fw_str(i8* %11, i8* %12, i32 128)
br label %14
14: ; preds = %18, %2
%15 = load i8*, i8** %7
%16 = call i8* @strchr(i8* %15, i8 signext 10)
store i8* %16, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i8*, i8** %8
store i8 0, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %7
br label %14
28: ; preds = %14
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %7
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %3
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%34 = call i32 @strcat(i8* %32, i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\22%s\22,\00"
@.str.1 = [5 x i8] c"\22%s\22\00"
define void @read_vmcmd(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8 0, i8* %0
%7 = call i32 @read_fw_str(i8* %5, i8* %1, i32 128)
%8 = call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i8* [ %16, %10 ], [ %8, %2 ]
%12 = phi i8* [ %15, %10 ], [ %5, %2 ]
store i8 0, i8* %11
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @strcat(i8* %0, i8* %6)
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = call i8* @strchr(i8* dereferenceable(1) %15, i8 signext 10)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %10
18: ; preds = %10, %2
%19 = phi i8* [ %5, %2 ], [ %15, %10 ]
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @strcat(i8* %0, i8* %6)
ret void
}