#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
unsigned int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned int is_process_repeat_run(unsigned int process_pid,
                                   char *process_name) {
  assert((process_pid > 0) && (process_name != NULL));
  DIR *dir = opendir("/proc");
  if (!dir) {
    fprintf(stderr, "Cannot open /proc");
    assert(0);
  }
  FILE *fp;
  struct dirent *next;
  char buffer[(256 + 32)] = {0};
  char process_file[256] = {0};
  unsigned int read_process_pid;
  char read_process_name[256] = {0};
  while ((next = readdir(dir)) != NULL) {
    if (strcmp(next->d_name, "..") == 0)
      continue;
    if (!isdigit(*next->d_name))
      continue;
    sprintf(process_file, "/proc/%s/status", next->d_name);
    if (!(fp = fopen(process_file, "r")))
      continue;
    memset(buffer, 0, (256 + 32));
    if (fgets(buffer, (256 + 32) - 1, fp) == NULL) {
      fclose(fp);
      continue;
    }
    fclose(fp);
    memset(read_process_name, 0, 256);
    sscanf(buffer, "%*s %s", read_process_name);
    if (strcmp(read_process_name, process_name) == 0) {
      read_process_pid = strtol(next->d_name, NULL, 0);
      if (read_process_pid != process_pid) {
        return read_process_pid;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_process_repeat_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x361(%rbp)
jbe    1202 <is_process_repeat_run+0x32>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x361(%rbp)
mov    -0x361(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    0xdf3(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1249 <is_process_repeat_run+0x79>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1090 <assert@plt>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x120,%edx
call   1060 <memset@plt>
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x360(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     13e7 <is_process_repeat_run+0x217>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd6b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12bb <is_process_repeat_run+0xeb>
jmp    1282 <is_process_repeat_run+0xb2>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    12d8 <is_process_repeat_run+0x108>
jmp    1282 <is_process_repeat_run+0xb2>
lea    -0x250(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
lea    0xd28(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x250(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1318 <is_process_repeat_run+0x148>
jmp    1282 <is_process_repeat_run+0xb2>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x120,%edx
call   1060 <memset@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x11f,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1358 <is_process_repeat_run+0x188>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1282 <is_process_repeat_run+0xb2>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x360(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x150(%rbp),%rdi
lea    -0x360(%rbp),%rdx
lea    0xc9e(%rip),%rsi
call   10d0 <sscanf@plt>
lea    -0x360(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13e2 <is_process_repeat_run+0x212>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x254(%rbp)
mov    -0x254(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     13dd <is_process_repeat_run+0x20d>
mov    -0x254(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <is_process_repeat_run+0x21e>
jmp    13e2 <is_process_repeat_run+0x212>
jmp    1282 <is_process_repeat_run+0xb2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_process_repeat_run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x338,%rsp
mov    %edi,0x4(%rsp)
test   %edi,%edi
setne  %al
mov    %rsi,0x8(%rsp)
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1090 <assert@plt>
lea    0xe06(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,%r13
test   %rax,%rax
jne    122f <is_process_repeat_run+0x5f>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1090 <assert@plt>
lea    0x210(%rsp),%rdi
xor    %r12d,%r12d
mov    $0x120,%edx
xor    %esi,%esi
call   1060 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %r13,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     145e <is_process_repeat_run+0x28e>
mov    %rax,%r14
lea    0xcc3(%rip),%r15
jmp    1374 <is_process_repeat_run+0x1a4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10c0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     145b <is_process_repeat_run+0x28b>
mov    (%r14),%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1360 <is_process_repeat_run+0x190>
mov    (%r14),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1360 <is_process_repeat_run+0x190>
mov    (%r14),%rdx
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc6d(%rip),%rsi
call   10f0 <sprintf@plt>
mov    %rbx,%rdi
lea    0xc6e(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1360 <is_process_repeat_run+0x190>
mov    %rax,%rbx
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x120,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    $0x11f,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rbp,%rbp
je     1360 <is_process_repeat_run+0x190>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0x210(%rsp),%rdi
lea    0xc05(%rip),%rsi
mov    %rbx,%rdx
call   10d0 <sscanf@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1360 <is_process_repeat_run+0x190>
mov    (%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtol@plt>
cmp    0x4(%rsp),%eax
je     1360 <is_process_repeat_run+0x190>
mov    %eax,%r12d
jmp    145e <is_process_repeat_run+0x28e>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x338,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Cannot open /proc\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [16 x i8] c"/proc/%s/status\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [7 x i8] c"%*s %s\00"
define i32 @is_process_repeat_run(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca [288 x i8]
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca [256 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%13 = load i32, i32* %4
%14 = icmp ugt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br label %18
18: ; preds = %15, %2
%19 = phi i1 [ false, %2 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @assert(i32 0)
br label %29
29: ; preds = %25, %18
%30 = bitcast [288 x i8]* %9 to i8*
%31 = bitcast [256 x i8]* %10 to i8*
%32 = bitcast [256 x i8]* %12 to i8*
br label %33
33: ; preds = %95, %69, %61, %51, %43, %29
%34 = load i32*, i32** %6
%35 = call %struct.dirent* @readdir(i32* %34)
store %struct.dirent* %35, %struct.dirent** %8
%36 = icmp ne %struct.dirent* %35, null
br i1 %36, label %37, label %96
37: ; preds = %33
%38 = load %struct.dirent*, %struct.dirent** %8
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %33
44: ; preds = %37
%45 = load %struct.dirent*, %struct.dirent** %8
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = load i8, i8* %47
%49 = call i32 @isdigit(i8 signext %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %44
br label %33
52: ; preds = %44
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%54 = load %struct.dirent*, %struct.dirent** %8
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %59, i32** %7
%60 = icmp ne i32* %59, null
br i1 %60, label %62, label %61
61: ; preds = %52
br label %33
62: ; preds = %52
%63 = getelementptr inbounds [288 x i8], [288 x i8]* %9, i64 0, i64 0
%64 = call i32 @memset(i8* %63, i32 0, i32 288)
%65 = getelementptr inbounds [288 x i8], [288 x i8]* %9, i64 0, i64 0
%66 = load i32*, i32** %7
%67 = call i32* @fgets(i8* %65, i32 287, i32* %66)
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
br label %33
72: ; preds = %62
%73 = load i32*, i32** %7
%74 = call i32 @fclose(i32* %73)
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%76 = call i32 @memset(i8* %75, i32 0, i32 256)
%77 = getelementptr inbounds [288 x i8], [288 x i8]* %9, i64 0, i64 0
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%79 = call i32 @sscanf(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %78)
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%81 = load i8*, i8** %5
%82 = call i64 @strcmp(i8* %80, i8* %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %95
84: ; preds = %72
%85 = load %struct.dirent*, %struct.dirent** %8
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = call i32 @strtol(i8* %87, i32* null, i32 0)
store i32 %88, i32* %11
%89 = load i32, i32* %11
%90 = load i32, i32* %4
%91 = icmp ne i32 %89, %90
br i1 %91, label %92, label %94
92: ; preds = %84
%93 = load i32, i32* %11
store i32 %93, i32* %3
br label %97
94: ; preds = %84
br label %95
95: ; preds = %94, %72
br label %33
96: ; preds = %33
store i32 0, i32* %3
br label %97
97: ; preds = %96, %92
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Cannot open /proc\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [16 x i8] c"/proc/%s/status\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [7 x i8] c"%*s %s\00"
define i32 @is_process_repeat_run(i32 %0, i8* %1) {
%3 = alloca [288 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = icmp ne i32 %0, 0
%7 = icmp ne i8* %1, null
%8 = and i1 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @assert(i32 0)
br label %17
17: ; preds = %13, %2
%18 = getelementptr inbounds [288 x i8], [288 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call %struct.dirent* @readdir(i32* %11)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %56, label %23
23: ; preds = %17, %44
%24 = phi %struct.dirent* [ %45, %44 ], [ %21, %17 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %44, label %29
29: ; preds = %23
%30 = load i8*, i8** %25
%31 = load i8, i8* %30
%32 = call i32 @isdigit(i8 signext %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %44, label %34
34: ; preds = %29
%35 = load i8*, i8** %25
%36 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = call i32 @memset(i8* %18, i32 0, i32 288)
%41 = call i32* @fgets(i8* %18, i32 287, i32* %37)
%42 = icmp eq i32* %41, null
%43 = call i32 @fclose(i32* %37)
br i1 %42, label %44, label %47
44: ; preds = %39, %47, %52, %23, %29, %34
%45 = call %struct.dirent* @readdir(i32* %11)
%46 = icmp eq %struct.dirent* %45, null
br i1 %46, label %56, label %23
47: ; preds = %39
%48 = call i32 @memset(i8* %20, i32 0, i32 256)
%49 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%50 = call i64 @strcmp(i8* %20, i8* %1)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %44
52: ; preds = %47
%53 = load i8*, i8** %25
%54 = call i32 @strtol(i8* nocapture %53, i32* null, i32 0)
%55 = icmp eq i32 %54, %0
br i1 %55, label %44, label %56
56: ; preds = %52, %44, %17
%57 = phi i32 [ 0, %17 ], [ 0, %44 ], [ %54, %52 ]
ret i32 %57
}