#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 Buf_len(char *);
char *Mem_alloc(int, char *, int);
scalar_t__ Mem_free(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *Buf_prependInt(char *buf, int x, int *out) {
  if (!buf)
    return NULL;
  int len = Buf_len(buf) + sizeof(int);
  char *buf2 = Mem_alloc(
      (len),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/buf.c",
      64);
  memcpy(buf2, &x, sizeof(int));
  strcpy(buf2 + sizeof(int), buf);
  ((void)(Mem_free((buf),
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/"
                   "heads/master/src/buf.c",
                   67),
          (buf) = 0));
  if (out)
    *out = len;
  buf2[len - 1] = '\0';
  return buf2;
}


x86 assembly (clang, -O0):
<Buf_prependInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <Buf_prependInt+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    1212 <Buf_prependInt+0xc2>
mov    -0x10(%rbp),%rdi
call   1040 <Buf_len@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    0xe69(%rip),%rsi
mov    $0x40,%edx
call   1070 <Mem_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x43,%edx
call   1060 <Mem_free@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f9 <Buf_prependInt+0xa9>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Buf_prependInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
test   %rdi,%rdi
je     11d6 <Buf_prependInt+0x86>
mov    %rdx,%r14
mov    %rdi,%rbx
call   1040 <Buf_len@plt>
mov    %eax,%r15d
lea    0x4(%r15),%ebp
lea    0xe83(%rip),%r13
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x40,%edx
call   1070 <Mem_alloc@plt>
mov    %rax,%r12
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    %r12,%rdi
add    $0x4,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x43,%edx
call   1060 <Mem_free@plt>
test   %r14,%r14
je     11c8 <Buf_prependInt+0x78>
mov    %ebp,(%r14)
add    $0x3,%r15d
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
jmp    11d9 <Buf_prependInt+0x89>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/buf.c\00"
define i8* @Buf_prependInt(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i8* null, i8** %4
br label %41
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i32 @Buf_len(i8* %14)
%16 = sext i32 %15 to i64
%17 = add i64 %16, 4
%18 = trunc i64 %17 to i32
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = call i8* @Mem_alloc(i32 %19, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 64)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 @memcpy(i8* %21, i32* %6, i32 4)
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = load i8*, i8** %5
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = call i64 @Mem_free(i8* %27, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 67)
store i8* null, i8** %5
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %13
%32 = load i32, i32* %8
%33 = load i32*, i32** %7
store i32 %32, i32* %33
br label %34
34: ; preds = %31, %13
%35 = load i8*, i8** %9
%36 = load i32, i32* %8
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %9
store i8* %40, i8** %4
br label %41
41: ; preds = %34, %12
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/buf.c\00"
define i8* @Buf_prependInt(i8* %0, i32 %1, i32* writeonly %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = icmp eq i8* %0, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = tail call i32 @Buf_len(i8* %0)
%8 = add i32 %7, 4
%9 = tail call i8* @Mem_alloc(i32 %8, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 64)
%10 = call i32 @memcpy(i8* %9, i32* %4, i32 4)
%11 = getelementptr inbounds i8, i8* %9, i64 4
%12 = call i32 @strcpy(i8* %11, i8* %0)
%13 = call i64 @Mem_free(i8* %0, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 67)
%14 = icmp eq i32* %2, null
br i1 %14, label %16, label %15
15: ; preds = %6
store i32 %8, i32* %2
br label %16
16: ; preds = %15, %6
%17 = add i32 %7, 3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %9, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %3, %16
%21 = phi i8* [ %9, %16 ], [ null, %3 ]
ret i8* %21
}