#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*/ free_string_shares(char **, int);
char *malloc(int);
char **split_string(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *generate_share_strings(char *secret, int n, int t) {
  char **result = split_string(secret, n, t);
  int len = strlen(secret);
  int key_len = 6 + 2 * len + 1;
  int i;
  char *shares = malloc(key_len * n + 1);
  for (i = 0; i < n; ++i) {
    sprintf(shares + i * key_len, "%s\n", result[i]);
  }
  free_string_shares(result, n);
  return shares;
}


x86 assembly (clang, -O0):
<generate_share_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <split_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
add    $0x6,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
imul   -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <generate_share_strings+0x9c>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe27(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <generate_share_strings+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <free_string_shares@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_share_strings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%rbp
call   1040 <split_string@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%ebp
add    $0x7,%ebp
mov    %ebp,%edi
imul   %ebx,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
jle    11cc <generate_share_strings+0x7c>
movslq %ebp,%rbx
mov    0xc(%rsp),%r14d
xor    %r15d,%r15d
lea    0xe5b(%rip),%r12
mov    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%r15,8),%rdx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <sprintf@plt>
add    $0x1,%r15
add    %rbx,%rbp
cmp    %r15,%r14
jne    11b0 <generate_share_strings+0x60>
mov    %r13,%rdi
mov    0xc(%rsp),%esi
call   1060 <free_string_shares@plt>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i8* @generate_share_strings(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = call i8** @split_string(i8* %12, i32 %13, i32 %14)
store i8** %15, i8*** %7
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = mul nsw i32 2, %18
%20 = add nsw i32 6, %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = load i32, i32* %5
%24 = mul nsw i32 %22, %23
%25 = add nsw i32 %24, 1
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %11
store i32 0, i32* %10
br label %27
27: ; preds = %44, %3
%28 = load i32, i32* %10
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = load i8*, i8** %11
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = mul nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
%38 = load i8**, i8*** %7
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %31
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %27
47: ; preds = %27
%48 = load i8**, i8*** %7
%49 = load i32, i32* %5
%50 = call i32 @free_string_shares(i8** %48, i32 %49)
%51 = load i8*, i8** %11
ret i8* %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define noalias i8* @generate_share_strings(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8** @split_string(i8* %0, i32 %1, i32 %2)
%5 = tail call i32 @strlen(i8* %0)
%6 = shl nsw i32 %5, 1
%7 = add nsw i32 %6, 7
%8 = mul nsw i32 %7, %1
%9 = add nsw i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %24
12: ; preds = %3
%13 = sext i32 %7 to i64
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 0, %12 ], [ %22, %15 ]
%17 = mul nsw i64 %16, %13
%18 = getelementptr inbounds i8, i8* %10, i64 %17
%19 = getelementptr inbounds i8*, i8** %4, i64 %16
%20 = load i8*, i8** %19
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %24, label %15
24: ; preds = %15, %3
%25 = tail call i32 @free_string_shares(i8** %4, i32 %1)
ret i8* %10
}