#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char *p;
  int i;
  p = malloc(30);
  strcpy(p, "not 30 bytes");
  printf("p = <%s>\n", p);
  if (argc == 2) {
    if (strcmp(argv[1], "-b") == 0)
      p[42] = 'a';
    else if (strcmp(argv[1], "-f") == 0) {
      free(p);
      p[0] = 'b';
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1e,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1201 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11c9 <main+0x79>
mov    -0x18(%rbp),%rax
movb   $0x61,0x2a(%rax)
jmp    11fc <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <main+0xa7>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movb   $0x62,(%rax)
jmp    11fc <main+0xac>
jmp    1201 <main+0xb1>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1e,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
cmp    $0x2,%ebp
jne    11c4 <main+0x74>
mov    0x8(%r14),%rdi
lea    0xe83(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    0x8(%r14),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11c4 <main+0x74>
mov    %rbx,%rdi
call   1030 <free@plt>
movb   $0x62,(%rbx)
jmp    11c4 <main+0x74>
movb   $0x61,0x2a(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"not 30 bytes\00"
@.str.1 = [10 x i8] c"p = <%s>\0A\00"
@.str.2 = [3 x i8] c"-b\00"
@.str.3 = [3 x i8] c"-f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 30)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %6
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %37
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 42
store i8 97, i8* %23
br label %36
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 98, i8* %34
br label %35
35: ; preds = %30, %24
br label %36
36: ; preds = %35, %21
br label %37
37: ; preds = %36, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"not 30 bytes\00"
@.str.1 = [10 x i8] c"p = <%s>\0A\00"
@.str.2 = [3 x i8] c"-b\00"
@.str.3 = [3 x i8] c"-f\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%4 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %3, i64 42
store i8 97, i8* %13
br label %20
14: ; preds = %7
%15 = load i8*, i8** %8
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @free(i8* %3)
store i8 98, i8* %3
br label %20
20: ; preds = %12, %18, %14, %2
ret i32 0
}