#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 strlen(char *);
int get_underline_for_string(char *uline, char *str) {
  char *ptr = (char *)NULL;
  int x = 0;
  for (ptr = uline, x = 0; x < (strlen(str) + 1); x++, ptr++) {
    *ptr = '-';
  }
  *ptr = '\0';
  return (strlen(uline) - 1);
}


x86 assembly (clang, -O0):
<get_underline_for_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    117e <get_underline_for_string+0x6e>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <get_underline_for_string+0x2e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_underline_for_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %r14,%rbx
test   %eax,%eax
js     1156 <get_underline_for_string+0x46>
mov    $0xffffffff,%ebp
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x2d,(%rbx)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%ebp
cmp    %eax,%ebp
jl     1140 <get_underline_for_string+0x30>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_underline_for_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i32 0, i32* %6
br label %8
8: ; preds = %16, %2
%9 = load i32, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = load i8*, i8** %5
store i8 45, i8* %15
br label %16
16: ; preds = %14
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
br label %8
21: ; preds = %8
%22 = load i8*, i8** %5
store i8 0, i8* %22
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
ret i32 %25
}

LLVM IR (-O2):
define i32 @get_underline_for_string(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ 0, %2 ]
%7 = phi i8* [ %9, %5 ], [ %0, %2 ]
store i8 45, i8* %7
%8 = add nuw nsw i32 %6, 1
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp slt i32 %6, %10
br i1 %11, label %5, label %12
12: ; preds = %5, %2
%13 = phi i8* [ %0, %2 ], [ %9, %5 ]
store i8 0, i8* %13
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, -1
ret i32 %15
}