#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*/ line;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ read(int, void *, int);
char *skipPrefix(char *);
char *getProgName() {
  int fdp;
  static char line[1024];
  if ((fdp = open("/proc/self/cmdline", 0, 0)) < 0) {
    return NULL;
  }
  if (read(fdp, (void *)&line, sizeof(line)) <= 0) {
    (void)close(fdp);
    return NULL;
  }
  (void)close(fdp);
  return skipPrefix(&line[0]);
}


x86 assembly (clang, -O0):
<getProgName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1171 <getProgName+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11bc <getProgName+0x7c>
mov    -0xc(%rbp),%edi
lea    0x2ed5(%rip),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     11a4 <getProgName+0x64>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    11bc <getProgName+0x7c>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
lea    0x2e9d(%rip),%rdi
call   1060 <skipPrefix@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProgName>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
js     118f <getProgName+0x4f>
mov    %eax,%ebx
lea    0x2eef(%rip),%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1030 <close@plt>
test   %r14,%r14
jle    118f <getProgName+0x4f>
lea    0x2ecd(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <skipPrefix@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@getProgName.line = internal global [1024 x i8] zeroinitializer
@.str = [19 x i8] c"/proc/self/cmdline\00"
define i8* @getProgName() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
store i32 %3, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %0
store i8* null, i8** %1
br label %17
6: ; preds = %0
%7 = load i32, i32* %2
%8 = call i64 @read(i32 %7, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getProgName.line, i32 0, i32 0), i32 1024)
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i32 @close(i32 %11)
store i8* null, i8** %1
br label %17
13: ; preds = %6
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = call i8* @skipPrefix(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getProgName.line, i64 0, i64 0))
store i8* %16, i8** %1
br label %17
17: ; preds = %13, %10, %5
%18 = load i8*, i8** %1
ret i8* %18
}

LLVM IR (-O2):
@getProgName.line = internal global [1024 x i8] zeroinitializer
@.str = [19 x i8] c"/proc/self/cmdline\00"
define i8* @getProgName() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = tail call i64 @read(i32 %1, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getProgName.line, i64 0, i64 0), i32 1024)
%5 = icmp slt i64 %4, 1
%6 = tail call i32 @close(i32 %1)
br i1 %5, label %9, label %7
7: ; preds = %3
%8 = tail call i8* @skipPrefix(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getProgName.line, i64 0, i64 0))
br label %9
9: ; preds = %3, %0, %7
%10 = phi i8* [ %8, %7 ], [ null, %0 ], [ null, %3 ]
ret i8* %10
}