#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*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ string_to_upper(char *, char *);
int strlen(char *);
int get_project_name_constant(char *project_name, char *name_constant) {
  char project_name_upper[512];
  int i;
  if (strlen(project_name) == 0)
    return -1;
  string_to_upper(project_name, project_name_upper);
  sprintf(name_constant, "BR2_PACKAGE_%s", project_name_upper);
  for (i = 0; i < strlen(project_name_upper); i++) {
    if (project_name_upper[i] == ' ') {
      project_name_upper[i] = '_';
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_project_name_constant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1161 <get_project_name_constant+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <get_project_name_constant+0xd1>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <string_to_upper@plt>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x224(%rbp)
mov    -0x224(%rbp),%eax
mov    %eax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x228(%rbp),%eax
cmp    %ecx,%eax
jge    11fa <get_project_name_constant+0xca>
movslq -0x224(%rbp),%rax
movsbl -0x220(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    11e1 <get_project_name_constant+0xb1>
movslq -0x224(%rbp),%rax
movb   $0x5f,-0x220(%rbp,%rax,1)
5f
jmp    11e6 <get_project_name_constant+0xb6>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    1192 <get_project_name_constant+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_project_name_constant>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     11a3 <get_project_name_constant+0x73>
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <string_to_upper@plt>
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1050 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    119f <get_project_name_constant+0x6f>
xor    %ebx,%ebx
mov    %rsp,%r14
jmp    1193 <get_project_name_constant+0x63>
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    119f <get_project_name_constant+0x6f>
cmpb   $0x20,(%rsp,%rbx,1)
jne    1180 <get_project_name_constant+0x50>
movb   $0x5f,(%rsp,%rbx,1)
jmp    1180 <get_project_name_constant+0x50>
xor    %eax,%eax
jmp    11a8 <get_project_name_constant+0x78>
mov    $0xffffffff,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"BR2_PACKAGE_%s\00"
define i32 @get_project_name_constant(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %40
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = call i32 @string_to_upper(i8* %13, i8* %14)
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 0, i32* %7
br label %19
19: ; preds = %36, %12
%20 = load i32, i32* %7
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %33
store i8 95, i8* %34
br label %35
35: ; preds = %31, %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %19
39: ; preds = %19
store i32 0, i32* %3
br label %40
40: ; preds = %39, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [15 x i8] c"BR2_PACKAGE_%s\00"
define i32 @get_project_name_constant(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %2
%8 = call i32 @string_to_upper(i8* %0, i8* %4)
%9 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = call i32 @strlen(i8* %4)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %7, %18
%13 = phi i64 [ %19, %18 ], [ 0, %7 ]
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 32
br i1 %16, label %17, label %18
17: ; preds = %12
store i8 95, i8* %14
br label %18
18: ; preds = %12, %17
%19 = add nuw nsw i64 %13, 1
%20 = call i32 @strlen(i8* %4)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %12, label %23
23: ; preds = %18, %7, %2
%24 = phi i32 [ -1, %2 ], [ 0, %7 ], [ 0, %18 ]
ret i32 %24
}