#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 */
int /*<<< orphan*/ add_pwd_to_path(char *);
int atoi(char *);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ increment_rank();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ whoami(char *);
int main(int argc, char **argv) {
  int n = 2;
  if (argc == 2) {
    n = atoi(argv[1]);
  }
  add_pwd_to_path(argv[0]);
  increment_rank();
  whoami("chaine");
  char buffer[20];
  sprintf(buffer, "%d", n);
  execlp("foo", "foo", buffer, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <add_pwd_to_path@plt>
mov    $0x0,%al
call   1050 <increment_rank@plt>
lea    0xe4f(%rip),%rdi
call   1040 <whoami@plt>
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe43(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x30(%rbp),%rdx
lea    0xe36(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    $0x2,%ebp
cmp    $0x2,%edi
jne    117e <main+0x1e>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
call   1030 <add_pwd_to_path@plt>
xor    %eax,%eax
call   1050 <increment_rank@plt>
lea    0xe6c(%rip),%rdi
call   1040 <whoami@plt>
lea    0xe67(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
lea    0xe56(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1080 <execlp@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"chaine\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"foo\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [20 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %10, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @add_pwd_to_path(i8* %18)
%20 = call i32 (...) @increment_rank()
%21 = call i32 @whoami(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%26 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32* null)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"chaine\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"foo\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ %8, %5 ], [ 2, %2 ]
%11 = load i8*, i8** %1
%12 = tail call i32 @add_pwd_to_path(i8* %11)
%13 = tail call i32 (...) @increment_rank()
%14 = tail call i32 @whoami(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%17 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32* null)
ret i32 0
}