#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*/ __MY_FREE(char *, char *, int);
int /*<<< orphan*/ my_err(char *, char *, int, long const);
scalar_t__ my_malloc(int);
int snprintf(char *, int, char *, long const);
int /*<<< orphan*/ util_breverse(char *, int);
char *util_long_to_comma_str(const long x) {
  char *str, *comma_str;
  int len, i, j, k;
  int max_commas;
  str = ((char *)my_malloc(sizeof(char) * 20));
  max_commas = (20 / 3);
  len = snprintf(str, 20 - max_commas, "%lu", x);
  if (len == 0) {
    my_err("%s:%d: could not write number %lu to string",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           715, x);
  }
  max_commas = len / 3;
  comma_str = ((char *)my_malloc(sizeof(char) * len + max_commas + 1));
  j = 0;
  k = 0;
  for (i = len - 1; i >= 0; i--) {
    comma_str[j] = str[i];
    k++;
    if (i > 0 && ((k % 3) == 0)) {
      j++;
      comma_str[j] = ',';
    }
    j++;
  }
  comma_str[j] = '\0';
  __MY_FREE(str,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
            "util.c",
            737);
  (str) = (void *)NULL;
  util_breverse(comma_str, j);
  return comma_str;
}


x86 assembly (clang, -O0):
<util_long_to_comma_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x6,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x14,%esi
sub    -0x2c(%rbp),%esi
mov    -0x8(%rbp),%rcx
lea    0xe78(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b6 <util_long_to_comma_str+0x66>
mov    -0x8(%rbp),%rcx
lea    0xe5f(%rip),%rdi
lea    0xe84(%rip),%rsi
mov    $0x2cb,%edx
call   1060 <my_err@plt>
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     126c <util_long_to_comma_str+0x11c>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1255 <util_long_to_comma_str+0x105>
mov    -0x28(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1255 <util_long_to_comma_str+0x105>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2c,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11f9 <util_long_to_comma_str+0xa9>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x2e1,%edx
call   1070 <__MY_FREE@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <util_breverse@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_long_to_comma_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r14
lea    0xe91(%rip),%rdx
mov    %rax,%rdi
mov    $0xe,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11a1 <util_long_to_comma_str+0x51>
lea    0xe77(%rip),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x2cb,%edx
mov    %rbx,%rcx
call   1060 <my_err@plt>
movslq %r15d,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    1234 <util_long_to_comma_str+0xe4>
mov    %r15d,%eax
add    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
mov    $0xffffffff,%edx
mov    $0x1,%esi
mov    $0xaaaaaaab,%r8d
jmp    1202 <util_long_to_comma_str+0xb2>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ecx
add    $0xffffffffffffffff,%rax
add    $0xffffffff,%edx
add    $0x1,%esi
cmp    $0xffffffff,%eax
je     1236 <util_long_to_comma_str+0xe6>
mov    %eax,%edi
movzbl (%r14,%rdi,1),%ebx
movslq %ecx,%rdi
mov    %bl,(%r12,%rdi,1)
test   %rax,%rax
je     11f0 <util_long_to_comma_str+0xa0>
mov    %esi,%ebx
imul   %r8,%rbx
shr    $0x21,%rbx
lea    (%rbx,%rbx,2),%ebx
add    %edx,%ebx
jne    11f0 <util_long_to_comma_str+0xa0>
movb   $0x2c,0x1(%r12,%rdi,1)
add    $0x1,%rdi
mov    %edi,%ecx
jmp    11f0 <util_long_to_comma_str+0xa0>
xor    %ecx,%ecx
movslq %ecx,%r15
movb   $0x0,(%r12,%r15,1)
lea    0xdeb(%rip),%rsi
mov    %r14,%rdi
mov    $0x2e1,%edx
call   1070 <__MY_FREE@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1050 <util_breverse@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lu\00"
@.str.1 = [44 x i8] c"%s:%d: could not write number %lu to string\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
define i8* @util_long_to_comma_str(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i64 %0, i64* %2
%10 = call i64 @my_malloc(i32 20)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
store i32 6, i32* %9
%12 = load i8*, i8** %3
%13 = load i32, i32* %9
%14 = sub nsw i32 20, %13
%15 = load i64, i64* %2
%16 = call i32 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %1
%20 = load i64, i64* %2
%21 = call i32 @my_err(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 715, i64 %20)
br label %22
22: ; preds = %19, %1
%23 = load i32, i32* %5
%24 = sdiv i32 %23, 3
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = add i64 %27, %29
%31 = add i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i64 @my_malloc(i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %4
store i32 0, i32* %7
store i32 0, i32* %8
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %68, %22
%38 = load i32, i32* %6
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %71
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
%52 = load i32, i32* %6
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %40
%55 = load i32, i32* %8
%56 = srem i32 %55, 3
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %54
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
%61 = load i8*, i8** %4
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 44, i8* %64
br label %65
65: ; preds = %58, %54, %40
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %68
68: ; preds = %65
%69 = load i32, i32* %6
%70 = add nsw i32 %69, -1
store i32 %70, i32* %6
br label %37
71: ; preds = %37
%72 = load i8*, i8** %4
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 0, i8* %75
%76 = load i8*, i8** %3
%77 = call i32 @__MY_FREE(i8* %76, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 737)
store i8* null, i8** %3
%78 = load i8*, i8** %4
%79 = load i32, i32* %7
%80 = call i32 @util_breverse(i8* %78, i32 %79)
%81 = load i8*, i8** %4
ret i8* %81
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lu\00"
@.str.1 = [44 x i8] c"%s:%d: could not write number %lu to string\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
define i8* @util_long_to_comma_str(i64 %0) {
%2 = tail call i64 @my_malloc(i32 20)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @snprintf(i8* %3, i32 14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @my_err(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 715, i64 %0)
br label %8
8: ; preds = %6, %1
%9 = sdiv i32 %4, 3
%10 = add i32 %4, 1
%11 = add i32 %10, %9
%12 = tail call i64 @my_malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp sgt i32 %4, 0
br i1 %14, label %15, label %40
15: ; preds = %8
%16 = zext i32 %4 to i64
br label %17
17: ; preds = %15, %36
%18 = phi i64 [ %16, %15 ], [ %21, %36 ]
%19 = phi i32 [ 0, %15 ], [ %27, %36 ]
%20 = phi i32 [ 0, %15 ], [ %38, %36 ]
%21 = add nsw i64 %18, -1
%22 = and i64 %21, 4294967295
%23 = getelementptr inbounds i8, i8* %3, i64 %22
%24 = load i8, i8* %23
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds i8, i8* %13, i64 %25
store i8 %24, i8* %26
%27 = add nuw nsw i32 %19, 1
%28 = icmp ne i64 %18, 1
%29 = urem i32 %27, 3
%30 = icmp eq i32 %29, 0
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %36
32: ; preds = %17
%33 = add nsw i32 %20, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %13, i64 %34
store i8 44, i8* %35
br label %36
36: ; preds = %32, %17
%37 = phi i32 [ %33, %32 ], [ %20, %17 ]
%38 = add nsw i32 %37, 1
%39 = icmp eq i32 %27, %4
br i1 %39, label %40, label %17
40: ; preds = %36, %8
%41 = phi i32 [ 0, %8 ], [ %38, %36 ]
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %13, i64 %42
store i8 0, i8* %43
%44 = tail call i32 @__MY_FREE(i8* %3, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 737)
%45 = tail call i32 @util_breverse(i8* %13, i32 %41)
ret i8* %13
}