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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strdup(char *);
char *strrchr(char *, char);
char *webroot() {
  FILE *in = fopen("conf", "rt");
  char buff[1000];
  fgets(buff, 1000, in);
  fclose(in);
  char *nl_ptr = strrchr(buff, '\n');
  if (nl_ptr != NULL)
    *nl_ptr = '\0';
  return strdup(buff);
}


x86 assembly (clang, -O0):
<webroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
lea    0xe9e(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x3f0(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x3f8(%rbp)
cmpq   $0x0,-0x3f8(%rbp)
je     11c0 <webroot+0x70>
mov    -0x3f8(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x3f0(%rbp),%rdi
call   1070 <strdup@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<webroot>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xe9f(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11a0 <webroot+0x50>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1070 <strdup@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"conf\00"
@.str.1 = [3 x i8] c"rt\00"
define i8* @webroot() {
%1 = alloca i32*
%2 = alloca [1000 x i8]
%3 = alloca i8*
%4 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = load i32*, i32** %1
%7 = call i32 @fgets(i8* %5, i32 1000, i32* %6)
%8 = load i32*, i32** %1
%9 = call i32 @fclose(i32* %8)
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%11 = call i8* @strrchr(i8* %10, i8 signext 10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = load i8*, i8** %3
store i8 0, i8* %15
br label %16
16: ; preds = %14, %0
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%18 = call i8* @strdup(i8* %17)
ret i8* %18
}

LLVM IR (-O2):
@.str = [5 x i8] c"conf\00"
@.str.1 = [3 x i8] c"rt\00"
define noalias i8* @webroot() {
%1 = alloca [1000 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = call i32 @fgets(i8* %3, i32 1000, i32* %2)
%5 = call i32 @fclose(i32* %2)
%6 = call i8* @strrchr(i8* %3, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i8 0, i8* %6
br label %9
9: ; preds = %8, %0
%10 = call i8* @strdup(i8* %3)
ret i8* %10
}