#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *my_malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
char *add_nvram_contents(char *url, char *folder) {
  ;
  char *nv;
  int nv_len;
  char *new_nv;
  char *nvp;
  nvp = my_malloc(strlen(url) + strlen(folder) + 2);
  sprintf(nvp, "%s>%s", url, folder);
  ;
  FILE *fp;
  fp = fopen("/opt/etc/smb_tokenfile", "r");
  if (fp == NULL) {
    nv = my_malloc(2);
    sprintf(nv, "");
  } else {
    fseek(fp, 0, SEEK_END);
    int file_size;
    file_size = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    nv = my_malloc(file_size + 2);
    fscanf(fp, "%[^\n]%*c", nv);
    fclose(fp);
  };
  nv_len = strlen(nv);
  if (nv_len) {
    new_nv = my_malloc(strlen(nv) + strlen(nvp) + 2);
    sprintf(new_nv, "%s<%s", nv, nvp);
  } else {
    new_nv = my_malloc(strlen(nvp) + 1);
    sprintf(new_nv, "%s", nvp);
  }
  free(nvp);
  free(nv);
  ;
  return new_nv;
}


x86 assembly (clang, -O0):
<add_nvram_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    0xe1f(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1227 <add_nvram_contents+0x97>
mov    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    1287 <add_nvram_contents+0xf7>
mov    -0x38(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x3c(%rbp),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12e2 <add_nvram_contents+0x152>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    130f <add_nvram_contents+0x17f>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_nvram_contents>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
call   1070 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r14
lea    0xe2e(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
lea    0xe1d(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1256 <add_nvram_contents+0xb6>
mov    %rax,%rbx
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %eax,%ebp
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
add    $0x2,%ebp
mov    %ebp,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r15
lea    0xdde(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1080 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    1266 <add_nvram_contents+0xc6>
mov    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1070 <strlen@plt>
test   %eax,%eax
je     12ab <add_nvram_contents+0x10b>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%rbx
lea    0xd8f(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
jmp    12c9 <add_nvram_contents+0x129>
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <my_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s>%s\00"
@.str.1 = [23 x i8] c"/opt/etc/smb_tokenfile\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [9 x i8] c"%[^\0A]%*c\00"
@.str.5 = [6 x i8] c"%s<%s\00"
@.str.6 = [3 x i8] c"%s\00"
define i8* @add_nvram_contents(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = add nsw i32 %15, 2
%17 = call i8* @my_malloc(i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %9
%23 = load i32*, i32** %9
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = call i8* @my_malloc(i32 2)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %46
29: ; preds = %2
%30 = load i32*, i32** %9
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %9
%34 = call i32 @ftell(i32* %33)
store i32 %34, i32* %10
%35 = load i32*, i32** %9
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 2
%40 = call i8* @my_malloc(i32 %39)
store i8* %40, i8** %5
%41 = load i32*, i32** %9
%42 = load i8*, i8** %5
%43 = call i32 @fscanf(i32* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32*, i32** %9
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %29, %25
%47 = load i8*, i8** %5
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %46
%52 = load i8*, i8** %5
%53 = call i32 @strlen(i8* %52)
%54 = load i8*, i8** %8
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %53, %55
%57 = add nsw i32 %56, 2
%58 = call i8* @my_malloc(i32 %57)
store i8* %58, i8** %7
%59 = load i8*, i8** %7
%60 = load i8*, i8** %5
%61 = load i8*, i8** %8
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %60, i8* %61)
br label %71
63: ; preds = %46
%64 = load i8*, i8** %8
%65 = call i32 @strlen(i8* %64)
%66 = add nsw i32 %65, 1
%67 = call i8* @my_malloc(i32 %66)
store i8* %67, i8** %7
%68 = load i8*, i8** %7
%69 = load i8*, i8** %8
%70 = call i32 (i8*, i8*, ...) @sprintf(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %63, %51
%72 = load i8*, i8** %8
%73 = call i32 @free(i8* %72)
%74 = load i8*, i8** %5
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %7
ret i8* %76
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s>%s\00"
@.str.1 = [23 x i8] c"/opt/etc/smb_tokenfile\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [9 x i8] c"%[^\0A]%*c\00"
@.str.5 = [6 x i8] c"%s<%s\00"
define i8* @add_nvram_contents(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i8* @my_malloc(i32 %6)
%8 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i8* @my_malloc(i32 2)
store i8 0, i8* %12
br label %23
13: ; preds = %2
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %9, i32 0, i32 %14)
%16 = tail call i32 @ftell(i32* %9)
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %9, i32 0, i32 %17)
%19 = add nsw i32 %16, 2
%20 = tail call i8* @my_malloc(i32 %19)
%21 = tail call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = tail call i32 @fclose(i32* %9)
br label %23
23: ; preds = %13, %11
%24 = phi i8* [ %12, %11 ], [ %20, %13 ]
%25 = tail call i32 @strlen(i8* %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %23
%28 = tail call i32 @strlen(i8* %24)
%29 = tail call i32 @strlen(i8* %7)
%30 = add i32 %28, 2
%31 = add i32 %30, %29
%32 = tail call i8* @my_malloc(i32 %31)
%33 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %24, i8* %7)
br label %39
34: ; preds = %23
%35 = tail call i32 @strlen(i8* %7)
%36 = add nsw i32 %35, 1
%37 = tail call i8* @my_malloc(i32 %36)
%38 = tail call i8* @strcpy(i8* dereferenceable(1) %37, i8* dereferenceable(1) %7)
br label %39
39: ; preds = %34, %27
%40 = phi i8* [ %32, %27 ], [ %37, %34 ]
%41 = tail call i32 @free(i8* %7)
%42 = tail call i32 @free(i8* %24)
ret i8* %40
}