#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 pid_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *make_proc_path(pid_t pid) {
  char *path = (char *)malloc(17 * sizeof(char));
  char spid[6];
  strcpy(path, "/proc/");
  sprintf(spid, "%d", pid);
  strcat(path, spid);
  strcat(path, "/stat");
  return path;
}


x86 assembly (clang, -O0):
<make_proc_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x11,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x16(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe90(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_proc_path>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    $0x11,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe9a(%rip),%rsi
lea    0xa(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"/proc/\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"/stat\00"
define i8* @make_proc_path(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [6 x i8]
store i32 %0, i32* %2
%5 = call i64 @malloc(i32 17)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@.str = [7 x i8] c"/proc/\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"/stat\00"
define i8* @make_proc_path(i32 %0) {
%2 = alloca [6 x i8]
%3 = tail call i64 @malloc(i32 17)
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%8 = call i32 @strcat(i8* %4, i8* %5)
%9 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i8* %4
}