#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*/ fprintf(int /*<<< orphan*/, char *, ...);
char *fsma_map_alloc(scalar_t__);
int /*<<< orphan*/ fsma_map_free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  char *ptr = NULL;
  if (argc != 2) {
    fprintf(stderr, "Syntax: %s <string>\n", argv[0]);
    return 1;
  }
  if (!(ptr = fsma_map_alloc(strlen(argv[1]) + 1))) {
    fprintf(stderr, "Failed to allocate memory\n");
    return 1;
  }
  strcpy(ptr, argv[1]);
  printf("Alloc'd memory contents: %s\n", ptr);
  fsma_map_free(ptr);
  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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b2 <main+0x52>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <fsma_map_alloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x9c>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xcd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fsma_map_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ad <main+0x4d>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <fsma_map_alloc@plt>
test   %rax,%rax
je     11c9 <main+0x69>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe97(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1060 <fsma_map_free@plt>
xor    %eax,%eax
jmp    11e5 <main+0x85>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11e0 <main+0x80>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Syntax: %s <string>\0A\00"
@.str.1 = [27 x i8] c"Failed to allocate memory\0A\00"
@.str.2 = [29 x i8] c"Alloc'd memory contents: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %36
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i8* @fsma_map_alloc(i64 %20)
store i8* %21, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %36
26: ; preds = %15
%27 = load i8*, i8** %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %27, i8* %30)
%32 = load i8*, i8** %6
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %6
%35 = call i32 @fsma_map_free(i8* %34)
store i32 0, i32* %3
br label %36
36: ; preds = %26, %23, %9
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Syntax: %s <string>\0A\00"
@.str.1 = [27 x i8] c"Failed to allocate memory\0A\00"
@.str.2 = [29 x i8] c"Alloc'd memory contents: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add nsw i64 %11, 1
%13 = tail call i8* @fsma_map_alloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %23
18: ; preds = %8
%19 = load i8*, i8** %9
%20 = tail call i32 @strcpy(i8* %13, i8* %19)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%22 = tail call i32 @fsma_map_free(i8* %13)
br label %23
23: ; preds = %18, %15, %4
%24 = phi i32 [ 1, %4 ], [ 0, %18 ], [ 1, %15 ]
ret i32 %24
}