#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[4], *p, *q;
  unsigned int size;
  int fd;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(-1);
  }
  do {
    if (!((fd = open(argv[1], O_RDONLY)) != -1)) {
      perror("open");
      exit(-1);
    }
  } while (0);
  do {
    if (!(read(fd, buffer, 4) == 4)) {
      perror("read");
      exit(-1);
    }
  } while (0);
  size = *(unsigned int *)buffer;
  p = malloc(size + 1);
  q = malloc(32);
  if (p != NULL && size >= 13) {
    p[13] = 'a';
  }
  free(p);
  free(q);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    11ea <main+0x7a>
lea    0xe37(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11ef <main+0x7f>
jmp    11f4 <main+0x84>
mov    -0x30(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     1224 <main+0xb4>
lea    0xe02(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1229 <main+0xb9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1269 <main+0xf9>
cmpl   $0xd,-0x2c(%rbp)
jb     1269 <main+0xf9>
mov    -0x20(%rbp),%rax
movb   $0x61,0xd(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11f4 <main+0x84>
mov    0x8(%rsi),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     120d <main+0x9d>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1216 <main+0xa6>
mov    0xc(%rsp),%r15d
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11d8 <main+0x68>
cmp    $0xd,%r15d
jb     11d8 <main+0x68>
movb   $0x61,0xd(%rbx)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rsi),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xdfe(%rip),%rdi
jmp    121d <main+0xad>
lea    0xdfa(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
br label %20
20: ; preds = %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %10
%26 = icmp ne i32 %25, -1
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %20
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load i32, i32* %10
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 4)
%36 = icmp eq i32 %35, 4
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %32
br label %41
41: ; preds = %40
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%43 = bitcast i8* %42 to i32*
%44 = load i32, i32* %43
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = add i32 %45, 1
%47 = call i8* @malloc(i32 %46)
store i8* %47, i8** %7
%48 = call i8* @malloc(i32 32)
store i8* %48, i8** %8
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %57
51: ; preds = %41
%52 = load i32, i32* %9
%53 = icmp uge i32 %52, 13
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 13
store i8 97, i8* %56
br label %57
57: ; preds = %54, %51, %41
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
%60 = load i8*, i8** %8
%61 = call i32 @free(i8* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = call i32 @read(i32 %14, i8* %4, i32 4)
%21 = icmp eq i32 %20, 4
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %19
%26 = load i32, i32* %3
%27 = add i32 %26, 1
%28 = tail call i8* @malloc(i32 %27)
%29 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%30 = icmp ne i8* %28, null
%31 = icmp ugt i32 %26, 12
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = getelementptr inbounds i8, i8* %28, i64 13
store i8 97, i8* %34
br label %35
35: ; preds = %33, %25
%36 = tail call i32 @free(i8* %28)
%37 = tail call i32 @free(i8* %29)
ret i32 0
}