#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 */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv, char **envp) {
  int i, j;
  j = 0;
  for (i = 0; envp[i]; i++) {
    if (strncmp("TEST_GDB", envp[i], 8) == 0) {
      printf("%s\n", envp[i]);
      j++;
    }
  }
  printf("Program found %d variables starting with TEST_GDB\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11b8 <main+0x98>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe92(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a5 <main+0x85>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11aa <main+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <main+0x28>
mov    -0x20(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdx),%rsi
test   %rsi,%rsi
je     117c <main+0x4c>
mov    %rdx,%rbx
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0xeb4(%rip),%r14
jmp    115c <main+0x2c>
xchg   %ax,%ax
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
je     117e <main+0x4e>
mov    %r14,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <main+0x20>
mov    -0x8(%rbx),%rdi
call   1040 <puts@plt>
add    $0x1,%ebp
jmp    1150 <main+0x20>
xor    %ebp,%ebp
lea    0xe84(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"TEST_GDB\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [51 x i8] c"Program found %d variables starting with TEST_GDB\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %10
10: ; preds = %35, %3
%11 = load i8**, i8*** %7
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %38
17: ; preds = %10
%18 = load i8**, i8*** %7
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %22, i32 8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %17
%26 = load i8**, i8*** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %34
34: ; preds = %25, %17
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %10
38: ; preds = %10
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"TEST_GDB\00"
@.str.2 = [51 x i8] c"Program found %d variables starting with TEST_GDB\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %23, label %6
6: ; preds = %3, %17
%7 = phi i64 [ %19, %17 ], [ 0, %3 ]
%8 = phi i8* [ %21, %17 ], [ %4, %3 ]
%9 = phi i8** [ %20, %17 ], [ %2, %3 ]
%10 = phi i32 [ %18, %17 ], [ 0, %3 ]
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %8, i32 8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = load i8*, i8** %9
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
%16 = add nsw i32 %10, 1
br label %17
17: ; preds = %6, %13
%18 = phi i32 [ %16, %13 ], [ %10, %6 ]
%19 = add nuw i64 %7, 1
%20 = getelementptr inbounds i8*, i8** %2, i64 %19
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %6
23: ; preds = %17, %3
%24 = phi i32 [ 0, %3 ], [ %18, %17 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}