#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 EXIT_FAILURE;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
scalar_t__ ioperm(unsigned short, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setgid(int /*<<< orphan*/);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int main(int argc, char **argv) {
  unsigned short int portbase = 0x378;
  if (argc < 2) {
    printf("Argument manquant : programme à lancer\n");
    exit(EXIT_FAILURE);
  }
  if (ioperm(portbase, 3, 1)) {
    perror("Accès au port refusé, échec");
    exit(EXIT_FAILURE);
  }
  setuid(getuid());
  setgid(getgid());
  execvp(argv[1], &argv[1]);
  perror("Echec d'exécution du programme");
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x378,-0x12(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d0 <main+0x40>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x3,%esi
mov    $0x1,%edx
movzwl -0x12(%rbp),%edi
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     1207 <main+0x77>
lea    0xe35(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%edi
call   10b0 <setuid@plt>
mov    $0x0,%al
call   1060 <getgid@plt>
mov    %eax,%edi
call   1070 <setgid@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1090 <execvp@plt>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    11f5 <main+0x65>
mov    %rsi,%rbx
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
jne    1203 <main+0x73>
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   10b0 <setuid@plt>
xor    %eax,%eax
call   1060 <getgid@plt>
mov    %eax,%edi
call   1070 <setgid@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1090 <execvp@plt>
lea    0xe3a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
jmp    120f <main+0x7f>
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Argument manquant : programme \C3\A0 lancer\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"Acc\C3\A8s au port refus\C3\A9, \C3\A9chec\00"
@.str.2 = [32 x i8] c"Echec d'ex\C3\A9cution du programme\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 888, i16* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i16, i16* %6
%15 = call i64 @ioperm(i16 zeroext %14, i32 3, i32 1)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 (...) @getuid()
%23 = call i32 @setuid(i32 %22)
%24 = call i32 (...) @getgid()
%25 = call i32 @setgid(i32 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = call i32 @execvp(i8* %28, i8** %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
ret i32 %33
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"Acc\C3\A8s au port refus\C3\A9, \C3\A9chec\00"
@.str.2 = [32 x i8] c"Echec d'ex\C3\A9cution du programme\00"
@str = [40 x i8] c"Argument manquant : programme \C3\A0 lancer\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = tail call i64 @ioperm(i16 zeroext 888, i32 3, i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = tail call i32 (...) @getuid()
%17 = tail call i32 @setuid(i32 %16)
%18 = tail call i32 (...) @getgid()
%19 = tail call i32 @setgid(i32 %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @execvp(i8* %21, i8** %20)
%23 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
ret i32 %24
}