#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 EXIT_SUCCESS;
int /*<<< orphan*/ delete (char *);
int /*<<< orphan*/ fatal_error(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *sndup(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int test_sndup(int argc, char *argv[]) {
  char *string;
  if (argc != 3)
    fatal_error("usage: %s %s <string>\n", argv[0], argv[1]);
  string =
      sndup("the string '%s' is %d characters long", argv[2], strlen(argv[2]));
  printf("%s\n", string);
  delete (string);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<test_sndup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     1184 <test_sndup+0x34>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe81(%rip),%rdi
call   1060 <fatal_error@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe6d(%rip),%rdi
call   1030 <sndup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <delete@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sndup>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
je     116c <test_sndup+0x1c>
mov    (%rbx),%rsi
mov    0x8(%rbx),%rdx
lea    0xe99(%rip),%rdi
call   1060 <fatal_error@plt>
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <sndup@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <delete@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"usage: %s %s <string>\0A\00"
@.str.1 = [38 x i8] c"the string '%s' is %d characters long\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @test_sndup(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 3
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @fatal_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %14)
br label %16
16: ; preds = %8, %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
%24 = call i8* @sndup(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @delete(i8* %27)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [23 x i8] c"usage: %s %s <string>\0A\00"
@.str.1 = [38 x i8] c"the string '%s' is %d characters long\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @test_sndup(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @fatal_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %7)
br label %9
9: ; preds = %4, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = tail call i8* @sndup(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i32 @delete(i8* %13)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}