#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 *basename(int /*<<< orphan*/);
int /*<<< orphan*/ dirname(char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char const *const, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *const);
int main(int argc, char *argv[]) {
  char buf[64], *env, *appname;
  const char *const mdbgvars[] = {"CRIT", "ERR", "WARN", "INFO"};
  unsigned i;
  if (argc != 2)
    return -1;
  appname = basename(dirname(argv[1]));
  printf("-DAPP_NAME=clondike-%s ", appname);
  for (i = 0; i < sizeof mdbgvars / sizeof mdbgvars[0]; i++) {
    sprintf(buf, "MDBG_%s_%s", appname, mdbgvars[i]);
    env = getenv(buf);
    if (env)
      printf("-DMDBG_%s=%s ", mdbgvars[i], env);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c90(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0x2c8d(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x68(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ab <main+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <dirname@plt>
mov    %eax,%edi
call   1060 <basename@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    $0x4,%rax
jae    125c <main+0x10c>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    -0x84(%rbp),%eax
mov    -0x80(%rbp,%rax,8),%rcx
lea    0xe22(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1243 <main+0xf3>
mov    -0x84(%rbp),%eax
mov    -0x80(%rbp,%rax,8),%rsi
mov    -0x58(%rbp),%rdx
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1248 <main+0xf8>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11df <main+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jne    1293 <main+0x143>
mov    0x8(%rsi),%rdi
call   1050 <dirname@plt>
mov    %eax,%edi
call   1060 <basename@plt>
mov    %rax,%r14
lea    0xe94(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%rsi
lea    0xe69(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ca <main+0x7a>
lea    0xe7d(%rip),%rdi
lea    0xe40(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5a(%rip),%rsi
lea    0xe2d(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     120b <main+0xbb>
lea    0xe3c(%rip),%rdi
lea    0xe04(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe19(%rip),%rsi
lea    0xdf0(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     124c <main+0xfc>
lea    0xdfb(%rip),%rdi
lea    0xdc7(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd8(%rip),%rsi
lea    0xdb4(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1291 <main+0x141>
lea    0xdba(%rip),%rdi
lea    0xd8b(%rip),%rsi
xor    %ebx,%ebx
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1293 <main+0x143>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"CRIT\00"
@.str.1 = [4 x i8] c"ERR\00"
@.str.2 = [5 x i8] c"WARN\00"
@.str.3 = [5 x i8] c"INFO\00"
@__const.main.mdbgvars = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [24 x i8] c"-DAPP_NAME=clondike-%s \00"
@.str.5 = [11 x i8] c"MDBG_%s_%s\00"
@.str.6 = [14 x i8] c"-DMDBG_%s=%s \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [64 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4 x i8*]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [4 x i8*]* %9 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %51
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @dirname(i8* %18)
%20 = call i8* @basename(i32 %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %21)
store i32 0, i32* %10
br label %23
23: ; preds = %47, %15
%24 = load i32, i32* %10
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %25, 4
br i1 %26, label %27, label %50
27: ; preds = %23
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %8
%30 = load i32, i32* %10
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %33)
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%36 = call i8* @getenv(i8* %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %46
39: ; preds = %27
%40 = load i32, i32* %10
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = load i8*, i8** %7
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %43, i8* %44)
br label %46
46: ; preds = %39, %27
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = add i32 %48, 1
store i32 %49, i32* %10
br label %23
50: ; preds = %23
store i32 0, i32* %3
br label %51
51: ; preds = %50, %14
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"CRIT\00"
@.str.1 = [4 x i8] c"ERR\00"
@.str.2 = [5 x i8] c"WARN\00"
@.str.3 = [5 x i8] c"INFO\00"
@.str.4 = [24 x i8] c"-DAPP_NAME=clondike-%s \00"
@.str.5 = [11 x i8] c"MDBG_%s_%s\00"
@.str.6 = [14 x i8] c"-DMDBG_%s=%s \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %35
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @dirname(i8* %8)
%10 = tail call i8* @basename(i32 %9)
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = call i8* @getenv(i8* %4)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %6
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %17
17: ; preds = %6, %15
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = call i8* @getenv(i8* %4)
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %23
23: ; preds = %21, %17
%24 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = call i8* @getenv(i8* %4)
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %29
29: ; preds = %27, %23
%30 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = call i8* @getenv(i8* %4)
%32 = icmp eq i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %35
35: ; preds = %29, %33, %2
%36 = phi i32 [ -1, %2 ], [ 0, %33 ], [ 0, %29 ]
ret i32 %36
}