#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*/ exec_and_send(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
void get_ps(int clientfd) {
  char *cmd = "ps -ao pid,cmd";
  char *fmt = "%s | grep -v \"%s\"";
  int size = strlen(fmt) + 2 * strlen(cmd);
  char buffer[size];
  snprintf(buffer, size, fmt, cmd, cmd);
  exec_and_send(clientfd, buffer);
}


x86 assembly (clang, -O0):
<get_ps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    (%rax,%rcx,2),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x10(%rbp),%r8
call   1040 <snprintf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1050 <exec_and_send@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ps>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
lea    0xeca(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0xeaa(%rip),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,2),%esi
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r12,%r8
call   1040 <snprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <exec_and_send@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"ps -ao pid,cmd\00"
@.str.1 = [18 x i8] c"%s | grep -v \22%s\22\00"
define void @get_ps(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = mul nsw i32 2, %11
%13 = add nsw i32 %9, %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %6
%17 = alloca i8, i64 %15
store i64 %15, i64* %7
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %17, i32 %18, i8* %19, i8* %20, i8* %21)
%23 = load i32, i32* %2
%24 = call i32 @exec_and_send(i32 %23, i8* %17)
%25 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"ps -ao pid,cmd\00"
@.str.1 = [18 x i8] c"%s | grep -v \22%s\22\00"
define void @get_ps(i32 %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = shl nsw i32 %3, 1
%5 = add nsw i32 %4, %2
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exec_and_send(i32 %0, i8* %7)
ret void
}