#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int start_cmd_trans(int fd, char *ext_arg, int cmd_count, char *stat) {
  int ret;
  char buf[4096];
  memset(buf, 0x0, sizeof(buf));
  sprintf(buf, "%s %s %04d", "--start-cmd-byJamesL", ext_arg, cmd_count);
  ret = write(fd, buf, strlen(buf));
  memset(buf, 0x0, sizeof(buf));
  ret = read(fd, buf, sizeof(buf));
  memcpy(stat, buf, sizeof(buf));
  return ret;
}


x86 assembly (clang, -O0):
<start_cmd_trans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    0xe5e(%rip),%rsi
lea    0xe62(%rip),%rdx
call   1080 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x103c(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x103c(%rbp),%edi
mov    -0x1038(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_cmd_trans>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0xe6d(%rip),%rsi
lea    0xe71(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r15d,%r8d
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <memcpy@plt>
mov    %ebp,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s %s %04d\00"
@.str.1 = [21 x i8] c"--start-cmd-byJamesL\00"
define i32 @start_cmd_trans(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 4096)
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
store i32 %21, i32* %9
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 4096)
%24 = load i32, i32* %5
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 4096)
store i32 %26, i32* %9
%27 = load i8*, i8** %8
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%29 = call i32 @memcpy(i8* %27, i8* %28, i32 4096)
%30 = load i32, i32* %9
ret i32 %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s %s %04d\00"
@.str.1 = [21 x i8] c"--start-cmd-byJamesL\00"
define i32 @start_cmd_trans(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 4096)
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2)
%9 = call i32 @strlen(i8* %6)
%10 = call i32 @write(i32 %0, i8* %6, i32 %9)
%11 = call i32 @memset(i8* %6, i32 0, i32 4096)
%12 = call i32 @read(i32 %0, i8* %6, i32 4096)
%13 = call i32 @memcpy(i8* %3, i8* %6, i32 4096)
ret i32 %12
}