#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 *find_next_token(char const **, unsigned int *);
scalar_t__ realpath(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned int);
char *variable_buffer_output(char *, char *, int);
char *func_realpath(char *o, char **argv,
                    const char *funcname __attribute__((unused))) {
  const char *p = argv[0];
  const char *path = 0;
  int doneany = 0;
  unsigned int len = 0;
  char in[1024];
  char out[1024];
  while ((path = find_next_token(&p, &len)) != 0) {
    if (len < 1024) {
      strncpy(in, path, len);
      in[len] = '\0';
      if (realpath(in, out)) {
        o = variable_buffer_output(o, out, strlen(out));
        o = variable_buffer_output(o, " ", 1);
        doneany = 1;
      }
    }
  }
  if (doneany)
    --o;
  return o;
}


x86 assembly (clang, -O0):
<func_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <find_next_token@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1253 <func_realpath+0x103>
cmpl   $0x400,-0x30(%rbp)
jae    124e <func_realpath+0xfe>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%eax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1050 <realpath@plt>
cmp    $0x0,%rax
je     1249 <func_realpath+0xf9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x840(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x830(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x840(%rbp),%rdi
mov    -0x838(%rbp),%rsi
mov    %eax,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x1,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    124e <func_realpath+0xfe>
jmp    1188 <func_realpath+0x38>
cmpl   $0x0,-0x2c(%rbp)
je     1269 <func_realpath+0x119>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_realpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%rbx
mov    (%rsi),%rax
mov    %rax,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1070 <find_next_token@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1224 <func_realpath+0xd4>
lea    0x10(%rsp),%r14
lea    0x410(%rsp),%r15
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbp
jmp    11c0 <func_realpath+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <find_next_token@plt>
test   %rax,%rax
je     1224 <func_realpath+0xd4>
mov    0x4(%rsp),%edx
cmp    $0x3ff,%edx
ja     11b0 <func_realpath+0x60>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strncpy@plt>
mov    0x4(%rsp),%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <realpath@plt>
test   %rax,%rax
je     11b0 <func_realpath+0x60>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <variable_buffer_output@plt>
mov    $0x1,%r12d
mov    %rax,%rdi
lea    0xdeb(%rip),%rsi
mov    $0x1,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,%rbx
jmp    11b0 <func_realpath+0x60>
cmp    $0x1,%r12d
adc    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @func_realpath(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
store i8* %15, i8** %7
store i8* null, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %43, %3
%17 = call i8* @find_next_token(i8** %7, i32* %10)
store i8* %17, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i32, i32* %10
%21 = icmp ult i32 %20, 1024
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %8
%25 = load i32, i32* %10
%26 = call i32 @strncpy(i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* %10
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%32 = call i64 @realpath(i8* %30, i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %22
%35 = load i8*, i8** %4
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = call i8* @variable_buffer_output(i8* %35, i8* %36, i32 %38)
store i8* %39, i8** %4
%40 = load i8*, i8** %4
%41 = call i8* @variable_buffer_output(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i8* %41, i8** %4
store i32 1, i32* %9
br label %42
42: ; preds = %34, %22
br label %43
43: ; preds = %42, %19
br label %16
44: ; preds = %16
%45 = load i32, i32* %9
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %4
br label %50
50: ; preds = %47, %44
%51 = load i8*, i8** %4
ret i8* %51
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @func_realpath(i8* %0, i8** nocapture %1, i8* nocapture readnone %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast i8** %4 to i8*
%9 = load i8*, i8** %1
store i8* %9, i8** %4
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = call i8* @find_next_token(i8** %4, i32* %5)
%14 = icmp eq i8* %13, null
br i1 %14, label %37, label %15
15: ; preds = %3, %32
%16 = phi i8* [ %35, %32 ], [ %13, %3 ]
%17 = phi i32 [ %34, %32 ], [ 0, %3 ]
%18 = phi i8* [ %33, %32 ], [ %0, %3 ]
%19 = load i32, i32* %5
%20 = icmp ult i32 %19, 1024
br i1 %20, label %21, label %32
21: ; preds = %15
%22 = call i32 @strncpy(i8* %11, i8* %16, i32 %19)
%23 = load i32, i32* %5
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @realpath(i8* %11, i8* %12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = call i32 @strlen(i8* %12)
%30 = call i8* @variable_buffer_output(i8* %18, i8* %12, i32 %29)
%31 = call i8* @variable_buffer_output(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %32
32: ; preds = %21, %28, %15
%33 = phi i8* [ %31, %28 ], [ %18, %21 ], [ %18, %15 ]
%34 = phi i32 [ 1, %28 ], [ %17, %21 ], [ %17, %15 ]
%35 = call i8* @find_next_token(i8** %4, i32* %5)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %15
37: ; preds = %32, %3
%38 = phi i8* [ %0, %3 ], [ %33, %32 ]
%39 = phi i32 [ 0, %3 ], [ %34, %32 ]
%40 = icmp ne i32 %39, 0
%41 = sext i1 %40 to i64
%42 = getelementptr i8, i8* %38, i64 %41
ret i8* %42
}