#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int get_next_sequence(char *path_filename) {
  FILE *p;
  char buffer[1024];
  char current_sequence[16];
  int next_sequence;
  sprintf(buffer,
          "ls -dt %s* | egrep \"#[0-9][0-9]*\" | head -1 | sed 's/^.*#//' "
          "2>/dev/null",
          path_filename);
  p = popen(buffer, "r");
  if (fgets(current_sequence, 15, p))
    next_sequence = atoi(current_sequence) + 1;
  else
    next_sequence = 100000;
  pclose(p);
  return next_sequence;
}


x86 assembly (clang, -O0):
<get_next_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8f(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xf,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c6 <get_next_sequence+0x76>
lea    -0x420(%rbp),%rdi
call   1060 <atoi@plt>
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11d0 <get_next_sequence+0x80>
movl   $0x186a0,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x424(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_sequence>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rdx
lea    0xe9d(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xed2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0xf,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11a6 <get_next_sequence+0x56>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
add    $0x1,%ebp
jmp    11ab <get_next_sequence+0x5b>
mov    $0x186a0,%ebp
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [73 x i8] c"ls -dt %s* | egrep \22#[0-9][0-9]*\22 | head -1 | sed 's/^.*#//' 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_next_sequence(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca [16 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i64 @fgets(i8* %12, i32 15, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %21
20: ; preds = %1
store i32 100000, i32* %6
br label %21
21: ; preds = %20, %16
%22 = load i32*, i32** %3
%23 = call i32 @pclose(i32* %22)
%24 = load i32, i32* %6
ret i32 %24
}

LLVM IR (-O2):
@.str = [73 x i8] c"ls -dt %s* | egrep \22#[0-9][0-9]*\22 | head -1 | sed 's/^.*#//' 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_next_sequence(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i64 @fgets(i8* %5, i32 15, i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i32 @atoi(i8* %5)
%12 = add nsw i32 %11, 1
br label %13
13: ; preds = %1, %10
%14 = phi i32 [ %12, %10 ], [ 100000, %1 ]
%15 = call i32 @pclose(i32* %7)
ret i32 %14
}