#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rtorrent_kill(char *);
int /*<<< orphan*/ screen_kill(char *);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ start_rtorrent(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ supprLock(char *);
int main(int argc, char *argv[]) {
  char nickname[50];
  if (argc < 2) {
    printf("ERREUR : Vous n'avez pas rentré de nom d'utilisateur en paramètre "
           "du programme.\n"
           "Usage : ./reboot-rtorrent <username>\n"
           "Le programme va quitter, bye.\n");
    return 101;
  }
  setuid(0);
  perror("setuid");
  strcpy(nickname, argv[1]);
  rtorrent_kill(nickname);
  screen_kill(nickname);
  supprLock(nickname);
  start_rtorrent(nickname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b8 <main+0x38>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
movl   $0x65,-0x4(%rbp)
jmp    1207 <main+0x87>
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xed0(%rip),%rdi
call   1090 <perror@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
call   1070 <rtorrent_kill@plt>
lea    -0x50(%rbp),%rdi
call   1080 <screen_kill@plt>
lea    -0x50(%rbp),%rdi
call   1060 <supprLock@plt>
lea    -0x50(%rbp),%rdi
call   1040 <start_rtorrent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jg     11a7 <main+0x27>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
mov    $0x65,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xe46(%rip),%rdi
call   1090 <perror@plt>
mov    0x8(%r14),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1070 <rtorrent_kill@plt>
mov    %r14,%rdi
call   1080 <screen_kill@plt>
mov    %r14,%rdi
call   1060 <supprLock@plt>
mov    %r14,%rdi
call   1050 <start_rtorrent@plt>
jmp    119d <main+0x1d>

LLVM IR (-O0):
@.str = [150 x i8] c"ERREUR : Vous n'avez pas rentr\C3\A9 de nom d'utilisateur en param\C3\A8tre du programme.\0AUsage : ./reboot-rtorrent <username>\0ALe programme va quitter, bye.\0A\00"
@.str.1 = [7 x i8] c"setuid\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str, i64 0, i64 0))
store i32 101, i32* %3
br label %27
11: ; preds = %2
%12 = call i32 @setuid(i32 0)
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %14, i8* %17)
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%20 = call i32 @rtorrent_kill(i8* %19)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%22 = call i32 @screen_kill(i8* %21)
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%24 = call i32 @supprLock(i8* %23)
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%26 = call i32 @start_rtorrent(i8* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %11, %9
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"setuid\00"
@str = [149 x i8] c"ERREUR : Vous n'avez pas rentr\C3\A9 de nom d'utilisateur en param\C3\A8tre du programme.\0AUsage : ./reboot-rtorrent <username>\0ALe programme va quitter, bye.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([149 x i8], [149 x i8]* @str, i64 0, i64 0))
br label %18
8: ; preds = %2
%9 = tail call i32 @setuid(i32 0)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %4, i8* %12)
%14 = call i32 @rtorrent_kill(i8* %4)
%15 = call i32 @screen_kill(i8* %4)
%16 = call i32 @supprLock(i8* %4)
%17 = call i32 @start_rtorrent(i8* %4)
br label %18
18: ; preds = %8, %6
%19 = phi i32 [ 101, %6 ], [ 0, %8 ]
ret i32 %19
}