#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 O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int *open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
char *set_initial_bitfield(int *fd, char *file_name, int num_pieces,
                           int piece_len, char **piece_shas) {
  int bitfield_len = num_pieces / 8;
  if (num_pieces % 8 != 0) {
    bitfield_len++;
  }
  printf(file_name);
  char *bitfield = malloc(bitfield_len);
  memset(bitfield, 0, bitfield_len);
  if ((fd = open(file_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IXUSR)) <
      0) {
    fprintf(stderr, "Error opening file to torrent");
  }
  return bitfield;
}


x86 assembly (clang, -O0):
<set_initial_bitfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1195 <set_initial_bitfield+0x45>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
or     (%rax),%esi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    0x2df2(%rip),%rax
or     (%rax),%edx
mov    0x2df1(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jae    1211 <set_initial_bitfield+0xc1>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_initial_bitfield>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0x7(%rdx),%ebp
test   %edx,%edx
cmovns %edx,%ebp
sar    $0x3,%ebp
and    $0x7,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ebp
mov    %rsi,%rdi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    0x2e78(%rip),%rax
mov    0x2e59(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2e(%rip),%rax
mov    0x2e37(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e34(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
call   1060 <open@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Error opening file to torrent\00"
define i8* @set_initial_bitfield(i32* %0, i8* %1, i32 %2, i32 %3, i8** %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8** %4, i8*** %10
%13 = load i32, i32* %8
%14 = sdiv i32 %13, 8
store i32 %14, i32* %11
%15 = load i32, i32* %8
%16 = srem i32 %15, 8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i32, i32* %11
%20 = add nsw i32 %19, 1
store i32 %20, i32* %11
br label %21
21: ; preds = %18, %5
%22 = load i8*, i8** %7
%23 = call i32 @printf(i8* %22)
%24 = load i32, i32* %11
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %12
%26 = load i8*, i8** %12
%27 = load i32, i32* %11
%28 = call i32 @memset(i8* %26, i32 0, i32 %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* @O_CREAT
%31 = load i32, i32* @O_RDWR
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %33, %34
%36 = load i32, i32* @S_IXUSR
%37 = or i32 %35, %36
%38 = call i32* @open(i8* %29, i32 %32, i32 %37)
store i32* %38, i32** %6
%39 = icmp ult i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %21
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %40, %21
%44 = load i8*, i8** %12
ret i8* %44
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@stderr = global i32 0
define i8* @set_initial_bitfield(i32* nocapture readnone %0, i8* nocapture %1, i32 %2, i32 %3, i8** nocapture readnone %4) {
%6 = sdiv i32 %2, 8
%7 = and i32 %2, 7
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i32
%10 = add nsw i32 %6, %9
%11 = tail call i32 @printf(i8* dereferenceable(1) %1)
%12 = tail call i8* @malloc(i32 %10)
%13 = tail call i32 @memset(i8* %12, i32 0, i32 %10)
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_RDWR
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IXUSR
%21 = or i32 %19, %20
%22 = tail call i32* @open(i8* %1, i32 %16, i32 %21)
ret i8* %12
}