#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 asprintf(char **, char *, ...);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char *path;
  int asprintlen = 0;
  if (argc < 2)
    return 111;
  asprintlen = asprintf(&path,
                        "/proc"
                        "/%s/stat",
                        argv[1]);
  assert(strlen(path) == asprintlen);
  printf("%s\n", path);
  asprintlen = asprintf(&path,
                        "/proc"
                        "/%d/stat",
                        strlen(argv[1]));
  assert(strlen(path) == asprintlen);
  printf("%s\n", path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1173 <main+0x33>
movl   $0x6f,-0x4(%rbp)
jmp    120d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x6f,%r12d
cmp    $0x2,%edi
jl     11ea <main+0xaa>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
lea    0xe97(%rip),%rsi
xor    %r12d,%r12d
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <asprintf@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rsi
lea    0xe6e(%rip),%r15
mov    %r15,%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
call   1030 <strlen@plt>
lea    0xe5a(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <asprintf@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    %ebx,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%s/stat\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [14 x i8] c"/proc/%d/stat\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 111, i32* %3
br label %37
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8**, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 %15, i32* %7
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = load i32, i32* %7
%19 = icmp eq i32 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %6
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = call i32 (i8**, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 %28, i32* %7
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = load i32, i32* %7
%32 = icmp eq i32 %30, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i8*, i8** %6
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %35)
store i32 0, i32* %3
br label %37
37: ; preds = %11, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%s/stat\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [14 x i8] c"/proc/%d/stat\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, %9
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = icmp eq i32 %21, %19
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %2, %6
%28 = phi i32 [ 0, %6 ], [ 111, %2 ]
ret i32 %28
}