#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 int /*<<< orphan*/ nickname;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ remove_lock_file(char *);
int /*<<< orphan*/ screen_irssi_kill(char *);
int /*<<< orphan*/ screen_rtorrent_kill(char *);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ start_irssi(char *);
int /*<<< orphan*/ start_rtorrent(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  char nickname[20];
  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");
  strncpy(nickname, argv[1], sizeof(nickname));
  screen_rtorrent_kill(nickname);
  remove_lock_file(nickname);
  start_rtorrent(nickname);
  if (argc > 2 && strcmp(argv[2], "irssi") == 0) {
    screen_irssi_kill(nickname);
    start_irssi(nickname);
  }
  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)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <main+0x38>
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
movl   $0x65,-0x4(%rbp)
jmp    125d <main+0xbd>
xor    %edi,%edi
call   10b0 <setuid@plt>
lea    0xeb0(%rip),%rdi
call   10a0 <perror@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rdi
call   1090 <screen_rtorrent_kill@plt>
lea    -0x30(%rbp),%rdi
call   1040 <remove_lock_file@plt>
lea    -0x30(%rbp),%rdi
call   1050 <start_rtorrent@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1256 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1256 <main+0xb6>
lea    -0x30(%rbp),%rdi
call   10c0 <screen_irssi_kill@plt>
lea    -0x30(%rbp),%rdi
call   1080 <start_irssi@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     11cd <main+0x2d>
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
mov    $0x65,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %edi,%edi
call   10b0 <setuid@plt>
lea    0xe1e(%rip),%rdi
call   10a0 <perror@plt>
mov    0x8(%r14),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1090 <screen_rtorrent_kill@plt>
mov    %r15,%rdi
call   1040 <remove_lock_file@plt>
mov    %r15,%rdi
call   1060 <start_rtorrent@plt>
cmp    $0x2,%ebp
je     11c0 <main+0x20>
mov    0x10(%r14),%rdi
lea    0xde4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11c0 <main+0x20>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10c0 <screen_irssi_kill@plt>
mov    %rbp,%rdi
call   1080 <start_irssi@plt>
jmp    11c0 <main+0x20>

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"
@.str.2 = [6 x i8] c"irssi\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 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 %39
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 [20 x i8], [20 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 @strncpy(i8* %14, i8* %17, i32 20)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%20 = call i32 @screen_rtorrent_kill(i8* %19)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%22 = call i32 @remove_lock_file(i8* %21)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%24 = call i32 @start_rtorrent(i8* %23)
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 2
br i1 %26, label %27, label %38
27: ; preds = %11
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%35 = call i32 @screen_irssi_kill(i8* %34)
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%37 = call i32 @start_irssi(i8* %36)
br label %38
38: ; preds = %33, %27, %11
store i32 0, i32* %3
br label %39
39: ; preds = %38, %9
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"setuid\00"
@.str.2 = [6 x i8] c"irssi\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 [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 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 %26
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 @strncpy(i8* %4, i8* %12, i32 20)
%14 = call i32 @screen_rtorrent_kill(i8* %4)
%15 = call i32 @remove_lock_file(i8* %4)
%16 = call i32 @start_rtorrent(i8* %4)
%17 = icmp eq i32 %0, 2
br i1 %17, label %26, label %18
18: ; preds = %8
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @screen_irssi_kill(i8* %4)
%25 = call i32 @start_irssi(i8* %4)
br label %26
26: ; preds = %8, %18, %23, %6
%27 = phi i32 [ 101, %6 ], [ 0, %23 ], [ 0, %18 ], [ 0, %8 ]
ret i32 %27
}