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

/* Variables and functions */
int execvp(char *, char **);
scalar_t__ getpid();
int /*<<< orphan*/ putenv(char *);
int snprintf(char *, int, char *, long);
int main(int argc, char *argv[]) {
  pid_t pid = getpid();
  char buf[50];
  int r;
  if (argc < 2)
    return -1;
  r = snprintf(buf, sizeof(buf), "GIO_LAUNCHED_DESKTOP_FILE_PID=%ld",
               (long)pid);
  if (r >= sizeof(buf))
    return -1;
  putenv(buf);
  return execvp(argv[1], argv + 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1177 <main+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <main+0x8e>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x32,%esi
lea    0xe75(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x54(%rbp)
movslq -0x54(%rbp),%rax
cmp    $0x32,%rax
jb     11ad <main+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <main+0x8e>
lea    -0x50(%rbp),%rdi
call   1050 <putenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <execvp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    $0xffffffff,%ebp
cmp    $0x2,%ebx
jl     1194 <main+0x54>
lea    0xe9b(%rip),%rdx
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
cmp    $0x31,%eax
ja     1194 <main+0x54>
mov    %rsp,%rdi
call   1050 <putenv@plt>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    %r14,%rsi
call   1060 <execvp@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"GIO_LAUNCHED_DESKTOP_FILE_PID=%ld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [50 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 (...) @getpid()
store i64 %9, i64* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %30
13: ; preds = %2
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%15 = load i64, i64* %6
%16 = call i32 @snprintf(i8* %14, i32 50, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = icmp uge i64 %18, 50
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 -1, i32* %3
br label %30
21: ; preds = %13
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%23 = call i32 @putenv(i8* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = call i32 @execvp(i8* %26, i8** %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %21, %20, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [34 x i8] c"GIO_LAUNCHED_DESKTOP_FILE_PID=%ld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [50 x i8]
%4 = tail call i64 (...) @getpid()
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = call i32 @snprintf(i8* %5, i32 50, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %4)
%9 = icmp ugt i32 %8, 49
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = call i32 @putenv(i8* %5)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @execvp(i8* %13, i8** %12)
br label %15
15: ; preds = %7, %2, %10
%16 = phi i32 [ %14, %10 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %16
}