#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*/ exit(int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ *strcpy(char *, char *);
int strlen(char *);
void getfullname(char **name, char *file, char *dir) {
  if (strcmp(dir, "/") == 0) {
    dir = "";
  }
  size_t len = strlen(dir) + 1 + strlen(file) + 1;
  *name = (char *)malloc(len * sizeof(char));
  if (*name == NULL) {
    perror(NULL);
    exit(1);
  }
  if (strcpy(*name, dir) == NULL) {
    perror(NULL);
    exit(1);
  }
  if (strcat(*name, "/") == NULL) {
    perror(NULL);
    exit(1);
  }
  if (strcat(*name, file) == NULL) {
    perror(NULL);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<getfullname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a9 <getfullname+0x39>
lea    0xe5c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1209 <getfullname+0x99>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
cmp    $0x0,%rax
jne    1236 <getfullname+0xc6>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xdbc(%rip),%rsi
call   1080 <strcat@plt>
cmp    $0x0,%rax
jne    1266 <getfullname+0xf6>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
cmp    $0x0,%rax
jne    1293 <getfullname+0x123>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfullname>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe78(%rip),%rsi
mov    %rdx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xe67(%rip),%rbx
cmovne %r12,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r12d,%eax
add    $0x2,%eax
movslq %eax,%rdi
call   1060 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1207 <getfullname+0x97>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
test   %rax,%rax
je     1207 <getfullname+0x97>
mov    (%r15),%rdi
lea    0xe1f(%rip),%rsi
call   1080 <strcat@plt>
test   %rax,%rax
je     1207 <getfullname+0x97>
mov    (%r15),%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
test   %rax,%rax
je     1207 <getfullname+0x97>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [1 x i8] zeroinitializer
define void @getfullname(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %12
12: ; preds = %11, %3
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = mul i64 %21, 1
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
%25 = load i8**, i8*** %4
store i8* %24, i8** %25
%26 = load i8**, i8*** %4
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %12
%30 = call i32 @perror(i32* null)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %12
%33 = load i8**, i8*** %4
%34 = load i8*, i8** %33
%35 = load i8*, i8** %6
%36 = call i32* @strcpy(i8* %34, i8* %35)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 @perror(i32* null)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = load i8**, i8*** %4
%43 = load i8*, i8** %42
%44 = call i32* @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @perror(i32* null)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %41
%50 = load i8**, i8*** %4
%51 = load i8*, i8** %50
%52 = load i8*, i8** %5
%53 = call i32* @strcat(i8* %51, i8* %52)
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = call i32 @perror(i32* null)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %49
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [1 x i8] zeroinitializer
define void @getfullname(i8** nocapture %0, i8* %1, i8* %2) {
%4 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %2
%7 = tail call i32 @strlen(i8* %6)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = sext i32 %10 to i64
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %0
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = tail call i32 @perror(i32* null)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = tail call i32* @strcpy(i8* %13, i8* %6)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @perror(i32* null)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = load i8*, i8** %0
%26 = tail call i32* @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = tail call i32 @perror(i32* null)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = load i8*, i8** %0
%33 = tail call i32* @strcat(i8* %32, i8* %1)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = tail call i32 @perror(i32* null)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %31
ret void
}