#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long,
                            int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int alloc_dcache(const char *cgroup, void *arg) {
  unsigned long i;
  struct stat st;
  char buf[128];
  for (i = 0; i < (unsigned long)arg; i++) {
    snprintf(buf, sizeof(buf),
             "/something-non-existent-with-a-long-name-%64lu-%d", i, getpid());
    stat(buf, &st);
  }
  return 0;
}


x86 assembly (clang, -O0):
<alloc_dcache>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    11bf <alloc_dcache+0x8f>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rcx
mov    %eax,%r8d
mov    $0x80,%esi
lea    0xe67(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114b <alloc_dcache+0x1b>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_dcache>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90,%rsp
test   %rsi,%rsi
je     11a1 <alloc_dcache+0x71>
cmp    $0x2,%rsi
mov    $0x1,%r13d
cmovae %rsi,%r13
lea    0xea6(%rip),%r14
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1040 <snprintf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <stat@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <alloc_dcache+0x40>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [50 x i8] c"/something-non-existent-with-a-long-name-%64lu-%d\00"
define i32 @alloc_dcache(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.stat
%7 = alloca [128 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %8
8: ; preds = %20, %2
%9 = load i64, i64* %5
%10 = load i8*, i8** %4
%11 = ptrtoint i8* %10 to i64
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%15 = load i64, i64* %5
%16 = call i32 (...) @getpid()
%17 = call i32 @snprintf(i8* %14, i32 128, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %15, i32 %16)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%19 = call i32 @stat(i8* %18, %struct.stat* %6)
br label %20
20: ; preds = %13
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %5
br label %8
23: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [50 x i8] c"/something-non-existent-with-a-long-name-%64lu-%d\00"
define i32 @alloc_dcache(i8* nocapture readnone %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca [128 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %1, null
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = ptrtoint i8* %1 to i64
%10 = call i64 @llvm.umax.i64(i64 %9, i64 1)
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %16, %11 ], [ 0, %8 ]
%13 = call i32 (...) @getpid()
%14 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %12, i32 %13)
%15 = call i32 @stat(i8* %6, %struct.stat* %3)
%16 = add nuw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11, %2
ret i32 0
}