#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int main(int argc, char *argv[]) {
  int i;
  char *line = malloc(10);
  char *longest = malloc(10);
  assert(line != NULL && longest != NULL && "memory error");
  for (i = 0; i < 10; i++) {
    line[i] = 'a';
  }
  copy(longest, line);
  free(line);
  free(longest);
  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)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     119c <main+0x5c>
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     119c <main+0x5c>
mov    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    119c <main+0x5c>
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11d4 <main+0x94>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b0 <main+0x70>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <copy@plt>
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   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
setne  %al
test   %r14,%r14
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
movabs $0x6161616161616161,%rax
61 61 61
mov    %rax,(%rbx)
movw   $0x6161,0x8(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <copy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"memory error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @malloc(i32 10)
store i8* %9, i8** %7
%10 = call i8* @malloc(i32 10)
store i8* %10, i8** %8
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
br label %17
17: ; preds = %16, %13, %2
%18 = phi i1 [ false, %13 ], [ false, %2 ], [ true, %16 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %29, %17
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 10
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 97, i8* %28
br label %29
29: ; preds = %24
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %21
32: ; preds = %21
%33 = load i8*, i8** %8
%34 = load i8*, i8** %7
%35 = call i32 @copy(i8* %33, i8* %34)
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%4 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%5 = icmp ne i8* %3, null
%6 = icmp ne i8* %4, null
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @copy(i8* %4, i8* %3)
%11 = tail call i32 @free(i8* %3)
%12 = tail call i32 @free(i8* %4)
ret i32 0
}