#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 *, char *, char *, ...);
char *strsep(char **, char *);
char *strstr(char *, char *);
void generate_defines(char *cflags) {
  char *Dpointer;
  char *definition;
  char *macroname = NULL;
  char *definition_value;
  Dpointer = cflags;
  while (Dpointer && (Dpointer = strstr(Dpointer, "-D"))) {
    Dpointer += 2;
    if ((definition = strsep(&Dpointer, " "))) {
      definition_value = definition;
      macroname = strsep(&definition_value, "=");
    }
    if (definition_value)
      printf("#if !defined(%s)\n#define %s %s\n#endif\n\n", macroname,
             macroname, definition_value);
    else
      printf("#if !defined(%s)\n#define %s\n#endif\n\n", macroname, macroname);
  }
}


x86 assembly (clang, -O0):
<generate_defines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     117a <generate_defines+0x4a>
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    118a <generate_defines+0x5a>
jmp    1215 <generate_defines+0xe5>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d0 <generate_defines+0xa0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11fa <generate_defines+0xca>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <generate_defines+0xe0>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114c <generate_defines+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_defines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
je     11e7 <generate_defines+0xb7>
lea    0xead(%rip),%rbx
lea    0xea9(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe9f(%rip),%rbp
lea    0x10(%rsp),%r12
xor    %r13d,%r13d
jmp    118e <generate_defines+0x5e>
lea    0xeb8(%rip),%rdi
mov    %r13,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11e7 <generate_defines+0xb7>
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11e7 <generate_defines+0xb7>
add    $0x2,%rax
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strsep@plt>
test   %rax,%rax
je     11c7 <generate_defines+0x97>
mov    %rax,0x10(%rsp)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strsep@plt>
mov    %rax,%r13
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     1170 <generate_defines+0x40>
lea    0xe2f(%rip),%rdi
mov    %r13,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1184 <generate_defines+0x54>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-D\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [40 x i8] c"#if !defined(%s)\0A#define %s %s\0A#endif\0A\0A\00"
@.str.4 = [37 x i8] c"#if !defined(%s)\0A#define %s\0A#endif\0A\0A\00"
define void @generate_defines(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %5
%7 = load i8*, i8** %2
store i8* %7, i8** %3
br label %8
8: ; preds = %37, %1
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %3
%14 = icmp ne i8* %13, null
br label %15
15: ; preds = %11, %8
%16 = phi i1 [ false, %8 ], [ %14, %11 ]
br i1 %16, label %17, label %38
17: ; preds = %15
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 2
store i8* %19, i8** %3
%20 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %4
store i8* %23, i8** %6
%24 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %24, i8** %5
br label %25
25: ; preds = %22, %17
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8*, i8** %5
%30 = load i8*, i8** %5
%31 = load i8*, i8** %6
%32 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %30, i8* %31)
br label %37
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %28
br label %8
38: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"-D\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [40 x i8] c"#if !defined(%s)\0A#define %s %s\0A#endif\0A\0A\00"
@.str.4 = [37 x i8] c"#if !defined(%s)\0A#define %s\0A#endif\0A\0A\00"
define void @generate_defines(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
%5 = bitcast i8** %3 to i8*
store i8* %0, i8** %2
%6 = icmp eq i8* %0, null
br i1 %6, label %29, label %7
7: ; preds = %1, %26
%8 = phi i8* [ %19, %26 ], [ null, %1 ]
%9 = phi i8* [ %27, %26 ], [ %0, %1 ]
%10 = call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %29, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %10, i64 2
store i8* %13, i8** %2
%14 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %12
store i8* %14, i8** %3
%17 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = phi i8* [ %17, %16 ], [ %8, %12 ]
%20 = load i8*, i8** %3
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %19, i8* %20)
br label %26
24: ; preds = %18
%25 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %19, i8* %19)
br label %26
26: ; preds = %24, %22
%27 = load i8*, i8** %2
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %7
29: ; preds = %7, %26, %1
ret void
}