#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
FILE *open_profile(FILE *in) {
  char path[256];
  strcpy(path, "user_profiles/");
  if (!fgets(path + 14, 512, in)) {
    return NULL;
  }
  if (path[strlen(path) - 1] == '\n') {
    path[strlen(path) - 1] = '\0';
  }
  return fopen(path, "r");
}


x86 assembly (clang, -O0):
<open_profile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
add    $0xe,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    1191 <open_profile+0x51>
movq   $0x0,-0x8(%rbp)
jmp    11e3 <open_profile+0xa3>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11cc <open_profile+0x8c>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_profile>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
lea    0xeac(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe(%rsp),%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     11a8 <open_profile+0x68>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    1197 <open_profile+0x57>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xe71(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
jmp    11aa <open_profile+0x6a>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"user_profiles/\00"
@.str.1 = [2 x i8] c"r\00"
define i32* @open_profile(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [256 x i8]
store i32* %0, i32** %3
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 14
%9 = load i32*, i32** %3
%10 = call i32 @fgets(i8* %8, i32 512, i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i32* null, i32** %2
br label %31
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %22, %13
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %2
br label %31
31: ; preds = %28, %12
%32 = load i32*, i32** %2
ret i32* %32
}

LLVM IR (-O2):
@.str = [15 x i8] c"user_profiles/\00"
@.str.1 = [2 x i8] c"r\00"
define noalias i32* @open_profile(i32* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 14
%6 = call i32 @fgets(i8* %5, i32 512, i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = call i32 @strlen(i8* %3)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15, %8
%21 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %1, %20
%23 = phi i32* [ %21, %20 ], [ null, %1 ]
ret i32* %23
}