#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 */
scalar_t__ malloc(int);
scalar_t__ read(int, char *, int);
char *cp_for_ll(char c, int sf, int fd) {
  char *stock;
  int i;
  i = 0;
  stock = (char *)malloc(sizeof(char) * sf % 16 + 1);
  while (read(fd, &c, 1)) {
    stock[i] = c;
    i++;
  }
  stock[i] = '\0';
  return (stock);
}


x86 assembly (clang, -O0):
<cp_for_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
and    $0xf,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
je     118d <cp_for_ll+0x6d>
mov    -0x1(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <cp_for_ll+0x36>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cp_for_ll>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %dil,0x7(%rsp)
and    $0xf,%esi
lea    0x1(%rsi),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0x7(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
je     1185 <cp_for_ll+0x65>
xor    %ebp,%ebp
lea    0x7(%rsp),%r14
nopl   0x0(%rax,%rax,1)
movzbl 0x7(%rsp),%eax
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jne    1160 <cp_for_ll+0x40>
mov    %ebp,%eax
jmp    1187 <cp_for_ll+0x67>
xor    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @cp_for_ll(i8 signext %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = urem i64 %11, 16
%13 = add i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
br label %17
17: ; preds = %21, %3
%18 = load i32, i32* %6
%19 = call i64 @read(i32 %18, i8* %4, i32 1)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i8, i8* %4
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %17
29: ; preds = %17
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %7
ret i8* %34
}

LLVM IR (-O2):
define i8* @cp_for_ll(i8 signext %0, i32 %1, i32 %2) {
%4 = alloca i8
store i8 %0, i8* %4
%5 = and i32 %1, 15
%6 = add nuw nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = call i64 @read(i32 %2, i8* %4, i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %3, %11
%12 = phi i64 [ %15, %11 ], [ 0, %3 ]
%13 = load i8, i8* %4
%14 = getelementptr inbounds i8, i8* %8, i64 %12
store i8 %13, i8* %14
%15 = add nuw i64 %12, 1
%16 = call i64 @read(i32 %2, i8* %4, i32 1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = and i64 %15, 4294967295
br label %20
20: ; preds = %18, %3
%21 = phi i64 [ 0, %3 ], [ %19, %18 ]
%22 = getelementptr inbounds i8, i8* %8, i64 %21
store i8 0, i8* %22
ret i8* %8
}