#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 *dirname(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main(int argc, const char **argv) {
  char buf[256];
  char pciescan[256];
  int rc = readlink("/proc/self/exe", buf, 256);
  setuid(0);
  snprintf(pciescan, 256, "%s/pciescan.sh", dirname(buf));
  fprintf(stderr, "Running %s\n", pciescan);
  system(pciescan);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x100,%edx
call   1030 <readlink@plt>
mov    %eax,-0x214(%rbp)
xor    %edi,%edi
call   1080 <setuid@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x110(%rbp),%rdi
call   1060 <dirname@plt>
mov    -0x220(%rbp),%rdi
mov    %rax,%rcx
mov    $0x100,%esi
lea    0xe41(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
lea    0xe91(%rip),%rdi
lea    0x100(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <readlink@plt>
xor    %edi,%edi
call   1080 <setuid@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xe75(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [15 x i8] c"%s/pciescan.sh\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"Running %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%10 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %9, i32 256)
store i32 %10, i32* %8
%11 = call i32 @setuid(i32 0)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = call i8* @dirname(i8* %13)
%15 = call i32 @snprintf(i8* %12, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i32 @system(i8* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [15 x i8] c"%s/pciescan.sh\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"Running %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5, i32 256)
%8 = tail call i32 @setuid(i32 0)
%9 = call i8* @dirname(i8* %5)
%10 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = call i32 @system(i8* %6)
ret i32 0
}