#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ *find_pid_by_name(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(scalar_t__ *);
int /*<<< orphan*/ stderr;
int pids_main(char *appname) {
  pid_t *pidList;
  pid_t *pl;
  int count = 0;
  pidList = find_pid_by_name(appname);
  for (pl = pidList; *pl; pl++) {
    count++;
    fprintf(stderr, "%u ", (unsigned)*pl);
  }
  if (count)
    fprintf(stderr, "\n");
  free(pidList);
  fprintf(stderr, "pid count: %d\n", count);
  return count;
}


x86 assembly (clang, -O0):
<pids_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <find_pid_by_name@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a0 <pids_main+0x70>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <pids_main+0x28>
cmpl   $0x0,-0x1c(%rbp)
je     11c1 <pids_main+0x91>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pids_main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1040 <find_pid_by_name@plt>
mov    %rax,%r14
mov    (%rax),%rdx
test   %rdx,%rdx
je     1190 <pids_main+0x60>
mov    0x2e91(%rip),%r12
lea    0xeaa(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%r14,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1160 <pids_main+0x30>
mov    (%r12),%edi
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1192 <pids_main+0x62>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%u \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [15 x i8] c"pid count: %d\0A\00"
define i32 @pids_main(i8* %0) {
%2 = alloca i8*
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i64* @find_pid_by_name(i8* %6)
store i64* %7, i64** %3
%8 = load i64*, i64** %3
store i64* %8, i64** %4
br label %9
9: ; preds = %21, %1
%10 = load i64*, i64** %4
%11 = load i64, i64* %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
%16 = load i32, i32* @stderr
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %13
%22 = load i64*, i64** %4
%23 = getelementptr inbounds i64, i64* %22, i32 1
store i64* %23, i64** %4
br label %9
24: ; preds = %9
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
%31 = load i64*, i64** %3
%32 = call i32 @free(i64* %31)
%33 = load i32, i32* @stderr
%34 = load i32, i32* %5
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%u \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [15 x i8] c"pid count: %d\0A\00"
define i32 @pids_main(i8* %0) {
%2 = tail call i64* @find_pid_by_name(i8* %0)
%3 = load i64, i64* %2
%4 = icmp eq i64 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %14, %5 ], [ %3, %1 ]
%7 = phi i32 [ %9, %5 ], [ 0, %1 ]
%8 = phi i64* [ %13, %5 ], [ %2, %1 ]
%9 = add nuw nsw i32 %7, 1
%10 = load i32, i32* @stderr
%11 = trunc i64 %6 to i32
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds i64, i64* %8, i64 1
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %1, %16
%20 = phi i32 [ %9, %16 ], [ 0, %1 ]
%21 = tail call i32 @free(i64* %2)
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 %20
}