#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 */

/* Variables and functions */
char *getProcName(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int findZygote() {
  int i = 1;
  char *output;
  for (i = 1; i < 1000; i++) {
    output = getProcName(i);
    printf("output is %s\n", output);
    char process[] = "zygote";
    if (output != NULL && strncmp(output, process, strlen(process)) == 0) {
      printf("found zygote\n");
      return i;
    }
  }
}


x86 assembly (clang, -O0):
<findZygote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1207 <findZygote+0xc7>
mov    -0x8(%rbp),%edi
call   1040 <getProcName@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0xe87(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xe81(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f4 <findZygote+0xb4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x17(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x17(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f4 <findZygote+0xb4>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <findZygote+0xc7>
jmp    11f9 <findZygote+0xb9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <findZygote+0x16>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findZygote>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
lea    0xe9c(%rip),%r14
mov    %rsp,%r15
jmp    117b <findZygote+0x2b>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x3e8,%ebx
je     11ce <findZygote+0x7e>
mov    %ebx,%edi
call   1050 <getProcName@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movl   $0x65746f,0x3(%rsp)
movl   $0x6f67797a,(%rsp)
test   %r12,%r12
je     1170 <findZygote+0x20>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <findZygote+0x20>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
jmp    11d3 <findZygote+0x83>
mov    $0x3e8,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"output is %s\0A\00"
@__const.findZygote.process = [7 x i8] c"zygote\00"
@.str.1 = [14 x i8] c"found zygote\0A\00"
define i32 @findZygote() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [7 x i8]
store i32 1, i32* %2
store i32 1, i32* %2
br label %5
5: ; preds = %27, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i8* @getProcName(i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = bitcast [7 x i8]* %4 to i8*
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i64 @strncmp(i8* %17, i8* %18, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %2
store i32 %25, i32* %1
br label %30
26: ; preds = %16, %8
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %5
30: ; preds = %23, %5
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"output is %s\0A\00"
@__const.findZygote.process = [7 x i8] c"zygote\00"
@str = [13 x i8] c"found zygote\00"
define i32 @findZygote() {
%1 = alloca [7 x i8]
%2 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %14
%4 = phi i32 [ 1, %0 ], [ %15, %14 ]
%5 = call i8* @getProcName(i32 %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp eq i8* %5, null
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = call i32 @strlen(i8* %2)
%10 = call i64 @strncmp(i8* %5, i8* %2, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %17
14: ; preds = %8, %3
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %3
17: ; preds = %14, %12
%18 = phi i32 [ %4, %12 ], [ 1000, %14 ]
ret i32 %18
}