#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int readlink(char *, char *, int);
int /*<<< orphan*/ send_errno(int /*<<< orphan*/);
int /*<<< orphan*/ send_string(char *);
int /*<<< orphan*/ send_success();
void do_readlink(int argc, char **argv) {
  char buf[256];
  int length;
  assert(argc == 1);
  length = readlink(argv[0], buf, sizeof(buf));
  if (length != -1) {
    send_success();
    buf[length] = 0;
    send_string(buf);
  } else
    send_errno(errno);
}


x86 assembly (clang, -O0):
<do_readlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <readlink@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
je     11c5 <do_readlink+0x75>
mov    $0x0,%al
call   1060 <send_success@plt>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1030 <send_string@plt>
jmp    11d3 <do_readlink+0x83>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1070 <send_errno@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_readlink>:
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x1,%edi
sete   %al
mov    %eax,%edi
call   1050 <assert@plt>
mov    (%rbx),%rdi
mov    %rsp,%rsi
mov    $0x100,%edx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     11a0 <do_readlink+0x50>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <send_success@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <send_string@plt>
add    $0x100,%rsp
pop    %rbx
ret
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
add    $0x100,%rsp
pop    %rbx
jmp    1070 <send_errno@plt>

LLVM IR (-O0):
@errno = global i32 0
define void @do_readlink(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [256 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%15 = call i32 @readlink(i8* %13, i8* %14, i32 256)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = call i32 (...) @send_success()
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = call i32 @send_string(i8* %23)
br label %28
25: ; preds = %2
%26 = load i32, i32* @errno
%27 = call i32 @send_errno(i32 %26)
br label %28
28: ; preds = %25, %18
ret void
}

LLVM IR (-O2):
@errno = global i32 0
define void @do_readlink(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i32 @readlink(i8* %8, i8* %4, i32 256)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = tail call i32 (...) @send_success()
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @send_string(i8* %4)
br label %19
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = tail call i32 @send_errno(i32 %17)
br label %19
19: ; preds = %16, %11
ret void
}