#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*/ time_t;
typedef void proctab;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int look_up_our_self();
void *proctab_new(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ stop_processes(void *, int);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void *stop_all_processes() {
  int n = 0;
  int self_pid = look_up_our_self();
  int max_tries = 5;
  struct proctab *sp = proctab_new(0);
  while (self_pid > 0 && n < max_tries && stop_processes(sp, self_pid)) {
    n++;
    do {
      char a[30];
      time_t now = time(NULL);
      strftime(a, 30, "%h %e %T ", localtime(&now));
      fprintf(stderr, "%s", a);
      fprintf(stderr, "calling stop_processes: %d\n", n);
    } while (0);
  }
  return sp;
}


x86 assembly (clang, -O0):
<stop_all_processes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <look_up_our_self@plt>
mov    %eax,-0x8(%rbp)
movl   $0x5,-0xc(%rbp)
xor    %edi,%edi
call   1040 <proctab_new@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x45(%rbp)
jle    11d1 <stop_all_processes+0x61>
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x45(%rbp)
jge    11d1 <stop_all_processes+0x61>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <stop_processes@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    11e1 <stop_all_processes+0x71>
jmp    1258 <stop_all_processes+0xe8>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x44(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%ecx
mov    $0x1e,%esi
lea    0xde7(%rip),%rdx
call   1090 <strftime@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    119b <stop_all_processes+0x2b>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stop_all_processes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
call   1050 <look_up_our_self@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1040 <proctab_new@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    13b9 <stop_all_processes+0x249>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <stop_processes@plt>
test   %rax,%rax
je     13b9 <stop_all_processes+0x249>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe3c(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    0x2e01(%rip),%r15
mov    (%r15),%edi
lea    0xe21(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xe10(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <stop_processes@plt>
test   %rax,%rax
je     13b9 <stop_all_processes+0x249>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xdc8(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    (%r15),%edi
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xda3(%rip),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <stop_processes@plt>
test   %rax,%rax
je     13b9 <stop_all_processes+0x249>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xd5b(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    (%r15),%edi
lea    0xd47(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xd36(%rip),%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <stop_processes@plt>
test   %rax,%rax
je     13b9 <stop_all_processes+0x249>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xcee(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    (%r15),%edi
lea    0xcda(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xcc9(%rip),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <stop_processes@plt>
test   %rax,%rax
je     13b9 <stop_all_processes+0x249>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xc85(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    (%r15),%edi
lea    0xc71(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xc60(%rip),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.proctab = type opaque
@.str = [10 x i8] c"%h %e %T \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [28 x i8] c"calling stop_processes: %d\0A\00"
define i8* @stop_all_processes() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.proctab*
%5 = alloca [30 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @look_up_our_self()
store i32 %7, i32* %2
store i32 5, i32* %3
%8 = call i8* @proctab_new(i32 0)
%9 = bitcast i8* %8 to %struct.proctab*
store %struct.proctab* %9, %struct.proctab** %4
br label %10
10: ; preds = %39, %0
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %1
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load %struct.proctab*, %struct.proctab** %4
%19 = bitcast %struct.proctab* %18 to i8*
%20 = load i32, i32* %2
%21 = call i64 @stop_processes(i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br label %23
23: ; preds = %17, %13, %10
%24 = phi i1 [ false, %13 ], [ false, %10 ], [ %22, %17 ]
br i1 %24, label %25, label %40
25: ; preds = %23
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
br label %28
28: ; preds = %25
%29 = call i32 @time(i32* null)
store i32 %29, i32* %6
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%31 = call i32 @localtime(i32* %6)
%32 = call i32 @strftime(i8* %30, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @stderr
%37 = load i32, i32* %1
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %28
br label %10
40: ; preds = %23
%41 = load %struct.proctab*, %struct.proctab** %4
%42 = bitcast %struct.proctab* %41 to i8*
ret i8* %42
}

LLVM IR (-O2):
@.str = [10 x i8] c"%h %e %T \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [28 x i8] c"calling stop_processes: %d\0A\00"
define i8* @stop_all_processes() {
%1 = alloca [30 x i8]
%2 = alloca i32
%3 = tail call i32 (...) @look_up_our_self()
%4 = tail call i8* @proctab_new(i32 0)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %59
6: ; preds = %0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%8 = bitcast i32* %2 to i8*
%9 = call i64 @stop_processes(i8* %4, i32 %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %59, label %11
11: ; preds = %6
%12 = call i32 @time(i32* null)
store i32 %12, i32* %2
%13 = call i32 @localtime(i32* %2)
%14 = call i32 @strftime(i8* %7, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 1)
%19 = call i64 @stop_processes(i8* %4, i32 %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %59, label %21
21: ; preds = %11
%22 = call i32 @time(i32* null)
store i32 %22, i32* %2
%23 = call i32 @localtime(i32* %2)
%24 = call i32 @strftime(i8* %7, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 2)
%29 = call i64 @stop_processes(i8* %4, i32 %3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %59, label %31
31: ; preds = %21
%32 = call i32 @time(i32* null)
store i32 %32, i32* %2
%33 = call i32 @localtime(i32* %2)
%34 = call i32 @strftime(i8* %7, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 3)
%39 = call i64 @stop_processes(i8* %4, i32 %3)
%40 = icmp eq i64 %39, 0
br i1 %40, label %59, label %41
41: ; preds = %31
%42 = call i32 @time(i32* null)
store i32 %42, i32* %2
%43 = call i32 @localtime(i32* %2)
%44 = call i32 @strftime(i8* %7, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 4)
%49 = call i64 @stop_processes(i8* %4, i32 %3)
%50 = icmp eq i64 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %41
%52 = call i32 @time(i32* null)
store i32 %52, i32* %2
%53 = call i32 @localtime(i32* %2)
%54 = call i32 @strftime(i8* %7, i32 30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %59
59: ; preds = %6, %11, %21, %31, %41, %51, %0
ret i8* %4
}