#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*/ ENAMETOOLONG;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, char const *,
                         char const *, char *);
int snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
const char *add_prefix(const char *orig, char *prefixed) {
  if ((strncmp(orig, "/proc", strlen("/proc")) != 0) &&
      (strncmp(orig, "/sys", strlen("/sys")) != 0))
    return orig;
  int status = snprintf(prefixed, 256, "%s%s", "/rootfs", orig);
  if (status < 1) {
    error(status, errno, "adding '%s' prefix to file path failed: '%s' -> '%s'",
          "/rootfs", orig, prefixed);
    return orig;
  } else if ((unsigned int)status >= 256) {
    error(status, ENAMETOOLONG,
          "'%s' got truncated when adding '%s' prefix: '%s'", orig, "/rootfs",
          prefixed);
    return orig;
  } else {
    return (const char *)prefixed;
  }
}


x86 assembly (clang, -O0):
<add_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xea1(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe8f(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bd <add_prefix+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe65(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bd <add_prefix+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <add_prefix+0x127>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe3a(%rip),%rdx
lea    0xe38(%rip),%rcx
call   1050 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    121e <add_prefix+0xde>
mov    -0x1c(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe13(%rip),%rdx
lea    0xe04(%rip),%rcx
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <add_prefix+0x127>
cmpl   $0x100,-0x1c(%rbp)
jb     125f <add_prefix+0x11f>
mov    -0x1c(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r9
lea    0xe07(%rip),%rdx
lea    0xdc3(%rip),%r8
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <add_prefix+0x127>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_prefix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118d <add_prefix+0x4d>
lea    0xe93(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11fd <add_prefix+0xbd>
lea    0xe77(%rip),%rdx
lea    0xe75(%rip),%rcx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r15,%r8
call   1050 <snprintf@plt>
test   %eax,%eax
jle    11d4 <add_prefix+0x94>
cmp    $0x100,%eax
jb     11fa <add_prefix+0xba>
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%esi
lea    0xe87(%rip),%rdx
lea    0xe43(%rip),%r8
mov    %eax,%edi
mov    %r15,%rcx
jmp    11f0 <add_prefix+0xb0>
mov    0x2e05(%rip),%rcx
mov    (%rcx),%esi
lea    0xe34(%rip),%rdx
lea    0xe25(%rip),%rcx
mov    %eax,%edi
mov    %r15,%r8
mov    %r14,%r9
call   1060 <error@plt>
jmp    11fd <add_prefix+0xbd>
mov    %r14,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"/proc\00"
@.str.1 = [5 x i8] c"/sys\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [8 x i8] c"/rootfs\00"
@errno = global i32 0
@.str.4 = [53 x i8] c"adding '%s' prefix to file path failed: '%s' -> '%s'\00"
@ENAMETOOLONG = global i32 0
@.str.5 = [49 x i8] c"'%s' got truncated when adding '%s' prefix: '%s'\00"
define i8* @add_prefix(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %4
store i8* %17, i8** %3
br label %43
18: ; preds = %11, %2
%19 = load i8*, i8** %5
%20 = load i8*, i8** %4
%21 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = load i32, i32* %6
%26 = load i32, i32* @errno
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i32 @error(i32 %25, i32 %26, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %27, i8* %28)
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %43
31: ; preds = %18
%32 = load i32, i32* %6
%33 = icmp uge i32 %32, 256
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* %6
%36 = load i32, i32* @ENAMETOOLONG
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i32 @error(i32 %35, i32 %36, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %43
41: ; preds = %31
%42 = load i8*, i8** %5
store i8* %42, i8** %3
br label %43
43: ; preds = %41, %34, %24, %16
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"/proc\00"
@.str.1 = [5 x i8] c"/sys\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [8 x i8] c"/rootfs\00"
@errno = global i32 0
@.str.4 = [53 x i8] c"adding '%s' prefix to file path failed: '%s' -> '%s'\00"
@ENAMETOOLONG = global i32 0
@.str.5 = [49 x i8] c"'%s' got truncated when adding '%s' prefix: '%s'\00"
define i8* @add_prefix(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6, %2
%11 = tail call i32 @snprintf(i8* %1, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = tail call i32 @error(i32 %11, i32 %14, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
br label %21
16: ; preds = %10
%17 = icmp ugt i32 %11, 255
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = load i32, i32* @ENAMETOOLONG
%20 = tail call i32 @error(i32 %11, i32 %19, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %21
21: ; preds = %13, %18, %16, %6
%22 = phi i8* [ %0, %6 ], [ %0, %13 ], [ %0, %18 ], [ %1, %16 ]
ret i8* %22
}