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

/* Variables and functions */
char *dirname(char *);
int execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
char *getenv(char *);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *strstr(char *, char *);
int main(int argc, char **argv) {
  char *puntero;
  char comando[1024];
  char comando_real[1024];
  int retorno;
  uid_t miuid;
  miuid = geteuid();
  setreuid(miuid, miuid);
  char *fichero = getenv("PHP_CGI_FILE");
  puntero = strstr(fichero, ";");
  if (puntero != NULL) {
    exit(99);
  }
  puntero = strstr(fichero, "|");
  if (puntero != NULL) {
    exit(99);
  }
  puntero = strstr(fichero, ".");
  if (puntero != NULL) {
    exit(99);
  }
  sprintf(comando, "./%s.karma_cgi.php", fichero);
  sprintf(comando_real, "%s/%s.karma_cgi.php", dirname(argv[0]), fichero);
  retorno = execl(comando_real, comando_real, NULL);
  exit(retorno);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,-0x828(%rbp)
mov    -0x828(%rbp),%edi
mov    -0x828(%rbp),%esi
call   1060 <setreuid@plt>
lea    0xe42(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f6 <main+0x76>
mov    $0x63,%edi
call   1080 <exit@plt>
mov    -0x830(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1222 <main+0xa2>
mov    $0x63,%edi
call   1080 <exit@plt>
mov    -0x830(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124e <main+0xce>
mov    $0x63,%edi
call   1080 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    -0x830(%rbp),%rdx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x820(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <dirname@plt>
mov    -0x838(%rbp),%rdi
mov    %rax,%rdx
mov    -0x830(%rbp),%rcx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x820(%rbp),%rdi
lea    -0x820(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <execl@plt>
mov    %eax,-0x824(%rbp)
mov    -0x824(%rbp),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1070 <setreuid@plt>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1231 <main+0xb1>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1231 <main+0xb1>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1231 <main+0xb1>
lea    0xe24(%rip),%rsi
lea    0x400(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    (%r14),%rdi
call   1050 <dirname@plt>
lea    0xe16(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   10a0 <execl@plt>
mov    %eax,%edi
call   1090 <exit@plt>
mov    $0x63,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"PHP_CGI_FILE\00"
@.str.1 = [2 x i8] c";\00"
@.str.2 = [2 x i8] c"|\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [19 x i8] c"./%s.karma_cgi.php\00"
@.str.5 = [20 x i8] c"%s/%s.karma_cgi.php\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @geteuid()
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = load i32, i32* %10
%15 = call i32 @setreuid(i32 %13, i32 %14)
%16 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %11
%17 = load i8*, i8** %11
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @exit(i32 99)
unreachable
23: ; preds = %2
%24 = load i8*, i8** %11
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @exit(i32 99)
unreachable
30: ; preds = %23
%31 = load i8*, i8** %11
%32 = call i8* @strstr(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @exit(i32 99)
unreachable
37: ; preds = %30
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = load i8*, i8** %11
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i8* @dirname(i8* %44)
%46 = load i8*, i8** %11
%47 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %45, i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i32 @execl(i8* %48, i8* %49, i32* null)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = call i32 @exit(i32 %51)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"PHP_CGI_FILE\00"
@.str.4 = [19 x i8] c"./%s.karma_cgi.php\00"
@.str.5 = [20 x i8] c"%s/%s.karma_cgi.php\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @geteuid()
%8 = tail call i32 @setreuid(i32 %7, i32 %7)
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i32 59)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @exit(i32 99)
unreachable
14: ; preds = %2
%15 = tail call i8* @strchr(i8* dereferenceable(1) %9, i32 124)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @exit(i32 99)
unreachable
19: ; preds = %14
%20 = tail call i8* @strchr(i8* dereferenceable(1) %9, i32 46)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @exit(i32 99)
unreachable
24: ; preds = %19
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%26 = load i8*, i8** %1
%27 = tail call i8* @dirname(i8* %26)
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %27, i8* %9)
%29 = call i32 @execl(i8* %6, i8* %6, i32* null)
%30 = call i32 @exit(i32 %29)
unreachable
}