#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int gl_pathc;
  int /*<<< orphan*/ *gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_MARK;
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *);
int frameq_getsetnum(char *dirname) {
  char pattern[512];
  glob_t pglob;
  int i;
  int max;
  int num;
  sprintf(pattern, "%s/set*", dirname);
  glob(pattern, GLOB_MARK, NULL, &pglob);
  if (pglob.gl_pathc < 1) {
    max = 0;
  } else {
    sprintf(pattern, "%s/set%%02d", dirname);
    max = 0;
    for (i = 0; i < pglob.gl_pathc; i++) {
      sscanf(pglob.gl_pathv[i], pattern, &num);
      if (num > max)
        max = num;
    }
  }
  globfree(&pglob);
  return max + 1;
}


x86 assembly (clang, -O0):
<frameq_getsetnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe9f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x220(%rbp),%rcx
call   1050 <glob@plt>
cmpl   $0x1,-0x220(%rbp)
jge    11a2 <frameq_getsetnum+0x62>
movl   $0x0,-0x228(%rbp)
jmp    123f <frameq_getsetnum+0xff>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0x0,-0x228(%rbp)
movl   $0x0,-0x224(%rbp)
mov    -0x224(%rbp),%eax
cmp    -0x220(%rbp),%eax
jge    123a <frameq_getsetnum+0xfa>
mov    -0x218(%rbp),%rax
movslq -0x224(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x210(%rbp),%rsi
lea    -0x22c(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x22c(%rbp),%eax
cmp    -0x228(%rbp),%eax
jle    1221 <frameq_getsetnum+0xe1>
mov    -0x22c(%rbp),%eax
mov    %eax,-0x228(%rbp)
jmp    1226 <frameq_getsetnum+0xe6>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    11cd <frameq_getsetnum+0x8d>
jmp    123f <frameq_getsetnum+0xff>
lea    -0x220(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x228(%rbp),%eax
add    $0x1,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frameq_getsetnum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%r14
lea    0xea9(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <glob@plt>
mov    $0x1,%ebp
cmpl   $0x0,0x10(%rsp)
jle    11ed <frameq_getsetnum+0xad>
lea    0xe76(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
cmpl   $0x0,0x10(%rsp)
jle    11ed <frameq_getsetnum+0xad>
xor    %ebx,%ebx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x18(%rsp),%rax
mov    (%rax,%rbx,4),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebp,%eax
cmovg  %eax,%ebp
add    $0x1,%rbx
movslq 0x10(%rsp),%rax
cmp    %rax,%rbx
jl     11c0 <frameq_getsetnum+0x80>
add    $0x1,%ebp
lea    0x10(%rsp),%rdi
call   1030 <globfree@plt>
mov    %ebp,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32* }
@.str = [8 x i8] c"%s/set*\00"
@GLOB_MARK = global i32 0
@.str.1 = [12 x i8] c"%s/set%%02d\00"
define i32 @frameq_getsetnum(i8* %0) {
%2 = alloca i8*
%3 = alloca [512 x i8]
%4 = alloca %struct.TYPE_4__
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @GLOB_MARK
%13 = call i32 @glob(i8* %11, i32 %12, i32* null, %struct.TYPE_4__* %4)
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 0, i32* %6
br label %46
18: ; preds = %1
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%20 = load i8*, i8** %2
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 0, i32* %6
store i32 0, i32* %5
br label %22
22: ; preds = %42, %18
%23 = load i32, i32* %5
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 0
%25 = load i32, i32* %24
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %45
27: ; preds = %22
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 1
%29 = load i32*, i32** %28
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%35 = call i32 @sscanf(i32 %33, i8* %34, i32* %7)
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = load i32, i32* %7
store i32 %40, i32* %6
br label %41
41: ; preds = %39, %27
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %22
45: ; preds = %22
br label %46
46: ; preds = %45, %17
%47 = call i32 @globfree(%struct.TYPE_4__* %4)
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
ret i32 %49
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32* }
@.str = [8 x i8] c"%s/set*\00"
@GLOB_MARK = global i32 0
@.str.1 = [12 x i8] c"%s/set%%02d\00"
define i32 @frameq_getsetnum(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca %struct.TYPE_4__
%4 = alloca i32
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.TYPE_4__* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @GLOB_MARK
%10 = call i32 @glob(i8* %5, i32 %9, i32* null, %struct.TYPE_4__* %3)
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, 1
br i1 %13, label %36, label %14
14: ; preds = %1
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = load i32, i32* %11
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %30, %20 ]
%22 = phi i32 [ 0, %18 ], [ %29, %20 ]
%23 = load i32*, i32** %19
%24 = getelementptr inbounds i32, i32* %23, i64 %21
%25 = load i32, i32* %24
%26 = call i32 @sscanf(i32 %25, i8* %5, i32* %4)
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, %22
%29 = select i1 %28, i32 %27, i32 %22
%30 = add nuw nsw i64 %21, 1
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %20, label %34
34: ; preds = %20
%35 = add i32 %29, 1
br label %36
36: ; preds = %34, %14, %1
%37 = phi i32 [ 1, %1 ], [ 1, %14 ], [ %35, %34 ]
%38 = call i32 @globfree(%struct.TYPE_4__* %3)
ret i32 %37
}