#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printAndFail(char *);
void addBytes(char *filename, int countOfBytes, char byte) {
  FILE *f = fopen(filename, "a+");
  if (!f) {
    printAndFail("Cannot create file");
  }
  char *bytes = (char *)malloc(countOfBytes + 1);
  int i;
  for (i = 0; i < countOfBytes; i++) {
    bytes[i] = byte;
  }
  if (fwrite(bytes, 1, countOfBytes, f) != countOfBytes) {
    printAndFail("Cannot write data 3");
  }
  fclose(f);
  free(bytes);
}


x86 assembly (clang, -O0):
<addBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <addBytes+0x3f>
lea    0xe69(%rip),%rdi
call   1050 <printAndFail@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <addBytes+0x7d>
mov    -0xd(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <addBytes+0x55>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmp    -0xc(%rbp),%eax
je     1207 <addBytes+0xa7>
lea    0xe14(%rip),%rdi
call   1050 <printAndFail@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addBytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    119b <addBytes+0x2b>
lea    0xe6d(%rip),%rdi
call   1050 <printAndFail@plt>
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    11b8 <addBytes+0x48>
mov    %ebx,%edx
movzbl %bpl,%esi
mov    %r15,%rdi
call   1060 <memset@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
cmp    %ebx,%eax
je     11da <addBytes+0x6a>
lea    0xe41(%rip),%rdi
call   1050 <printAndFail@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"a+\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@.str.2 = [20 x i8] c"Cannot write data 3\00"
define void @addBytes(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %8
store i32 0, i32* %9
br label %21
21: ; preds = %31, %16
%22 = load i32, i32* %9
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i8, i8* %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %25
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %21
34: ; preds = %21
%35 = load i8*, i8** %8
%36 = load i32, i32* %5
%37 = load i32*, i32** %7
%38 = call i32 @fwrite(i8* %35, i32 1, i32 %36, i32* %37)
%39 = load i32, i32* %5
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %34
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"a+\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@.str.2 = [20 x i8] c"Cannot write data 3\00"
define void @addBytes(i8* nocapture %0, i32 %1, i8 signext %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = add nsw i32 %1, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %8
%16 = tail call i32 @fwrite(i8* %11, i32 1, i32 %1, i32* %4)
%17 = icmp eq i32 %16, %1
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = tail call i32 @fclose(i32* %4)
%22 = tail call i32 @free(i8* %11)
ret void
}