#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 *);
int /*<<< orphan*/ gmk_alloc(size_t);
char *memcpy(int /*<<< orphan*/, char *, size_t);
char *realpath(char *, int /*<<< orphan*/ *);
int strlen(char *);
char *func_realpath(const char *nm, unsigned int argc, char **argv) {
  if (argc != 1)
    return NULL;
  char *path = realpath(argv[0], NULL);
  if (path == NULL)
    return NULL;
  size_t l = strlen(path) + 1;
  char *res = memcpy(gmk_alloc(l), path, l);
  free(path);
  return res;
}


x86 assembly (clang, -O0):
<func_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     117a <func_realpath+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <func_realpath+0x95>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <realpath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <func_realpath+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <func_realpath+0x95>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <gmk_alloc@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <memcpy@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_realpath>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%esi
jne    119e <func_realpath+0x4e>
mov    (%rdx),%rdi
xor    %esi,%esi
call   1060 <realpath@plt>
test   %rax,%rax
je     119e <func_realpath+0x4e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r14
mov    %r14,%rdi
call   1050 <gmk_alloc@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <memcpy@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
jmp    11a0 <func_realpath+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @func_realpath(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %3
store i8* null, i8** %4
br label %35
14: ; preds = %3
%15 = load i8**, i8*** %7
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i8* @realpath(i8* %17, i32* null)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %14
store i8* null, i8** %4
br label %35
22: ; preds = %14
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
store i64 %26, i64* %9
%27 = load i64, i64* %9
%28 = call i32 @gmk_alloc(i64 %27)
%29 = load i8*, i8** %8
%30 = load i64, i64* %9
%31 = call i8* @memcpy(i32 %28, i8* %29, i64 %30)
store i8* %31, i8** %10
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %10
store i8* %34, i8** %4
br label %35
35: ; preds = %22, %21, %13
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @func_realpath(i8* nocapture readnone %0, i32 %1, i8** nocapture %2) {
%4 = icmp eq i32 %1, 1
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = load i8*, i8** %2
%7 = tail call i8* @realpath(i8* %6, i32* null)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %5
%10 = tail call i32 @strlen(i8* %7)
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = tail call i32 @gmk_alloc(i64 %12)
%14 = tail call i8* @memcpy(i32 %13, i8* %7, i64 %12)
%15 = tail call i32 @free(i8* %7)
br label %16
16: ; preds = %9, %5, %3
%17 = phi i8* [ null, %3 ], [ %14, %9 ], [ null, %5 ]
ret i8* %17
}