#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 */
char *_mmatic_alloc(void *, scalar_t__, char const *, unsigned int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *_mmatic_strdup(void *mgr, const char *s, const char *cfile,
                     unsigned int cline) {
  char *newm;
  if (!s)
    return NULL;
  newm = _mmatic_alloc(mgr, strlen(s) + 1, cfile, cline);
  strcpy(newm, s);
  return newm;
}


x86 assembly (clang, -O0):
<_mmatic_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115f <_mmatic_strdup+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <_mmatic_strdup+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <_mmatic_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mmatic_strdup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1172 <_mmatic_strdup+0x42>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <_mmatic_alloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1174 <_mmatic_strdup+0x44>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @_mmatic_strdup(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %4
store i8* null, i8** %5
br label %26
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = call i8* @_mmatic_alloc(i8* %15, i64 %18, i8* %19, i32 %20)
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = load i8*, i8** %7
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %10
store i8* %25, i8** %5
br label %26
26: ; preds = %14, %13
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
define i8* @_mmatic_strdup(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = tail call i64 @strlen(i8* %1)
%8 = add nsw i64 %7, 1
%9 = tail call i8* @_mmatic_alloc(i8* %0, i64 %8, i8* %2, i32 %3)
%10 = tail call i32 @strcpy(i8* %9, i8* %1)
br label %11
11: ; preds = %4, %6
%12 = phi i8* [ %9, %6 ], [ null, %4 ]
ret i8* %12
}