#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int pids_cmdline(int pid, char *cmdline) {
  int fd;
  sprintf(cmdline, "/proc/%d/cmdline", pid);
  fd = open(cmdline, O_RDONLY);
  cmdline[0] = '\0';
  if (fd != -1) {
    read(fd, cmdline, 1024);
    cmdline[1024] = '\0';
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<pids_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea3(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0xffffffff,-0x14(%rbp)
je     11ac <pids_cmdline+0x6c>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x400(%rax)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pids_cmdline>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%edx
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
movb   $0x0,(%rbx)
cmp    $0xffffffff,%eax
je     118f <pids_cmdline+0x4f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
movb   $0x0,0x400(%rbx)
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@O_RDONLY = global i32 0
define i32 @pids_cmdline(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i32, i32* %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %5
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = call i32 @read(i32 %17, i8* %18, i32 1024)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1024
store i8 0, i8* %21
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
br label %24
24: ; preds = %16, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@O_RDONLY = global i32 0
define i32 @pids_cmdline(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %1, i32 %4)
store i8 0, i8* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @read(i32 %5, i8* %1, i32 1024)
%9 = getelementptr inbounds i8, i8* %1, i64 1024
store i8 0, i8* %9
%10 = tail call i32 @close(i32 %5)
br label %11
11: ; preds = %7, %2
ret i32 0
}