#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 inb(int);
int /*<<< orphan*/ ioperm(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setuid(int /*<<< orphan*/);
int main(void) {
  if (setuid(0) < 0) {
    printf("Program musi byt spusten rootem\n");
    return (0);
  }
  ioperm(0x378, 3, 1);
  ioperm(0x378 + 1, 3, 1);
  ioperm(0x378 + 2, 3, 1);
  printf("DATA: %4d\n", inb(0x378));
  printf("STATUS: %4d\n", inb(0x378 + 1));
  printf("CONTROL: %4d\n", inb(0x378 + 2));
  ioperm(0x378, 3, 0);
  ioperm(0x378 + 1, 3, 0);
  ioperm(0x378 + 2, 3, 0);
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <setuid@plt>
cmp    $0x0,%rax
jge    117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124c <main+0x10c>
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <ioperm@plt>
mov    $0x379,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <ioperm@plt>
mov    $0x37a,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <ioperm@plt>
mov    $0x378,%edi
call   1050 <inb@plt>
mov    %eax,%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x379,%edi
call   1050 <inb@plt>
mov    %eax,%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x37a,%edi
call   1050 <inb@plt>
mov    %eax,%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x378,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <ioperm@plt>
mov    $0x379,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <ioperm@plt>
mov    $0x37a,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <ioperm@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
call   1080 <setuid@plt>
test   %rax,%rax
js     123a <main+0xda>
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1060 <ioperm@plt>
mov    $0x379,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1060 <ioperm@plt>
mov    $0x37a,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1060 <ioperm@plt>
mov    $0x378,%edi
call   1070 <inb@plt>
lea    0xe42(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x379,%edi
call   1070 <inb@plt>
lea    0xe33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x37a,%edi
call   1070 <inb@plt>
lea    0xe26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x378,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1060 <ioperm@plt>
mov    $0x379,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1060 <ioperm@plt>
mov    $0x37a,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1060 <ioperm@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1246 <main+0xe6>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Program musi byt spusten rootem\0A\00"
@.str.1 = [11 x i8] c"DATA: %4d\0A\00"
@.str.2 = [13 x i8] c"STATUS: %4d\0A\00"
@.str.3 = [14 x i8] c"CONTROL: %4d\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @setuid(i32 0)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %20
6: ; preds = %0
%7 = call i32 @ioperm(i32 888, i32 3, i32 1)
%8 = call i32 @ioperm(i32 889, i32 3, i32 1)
%9 = call i32 @ioperm(i32 890, i32 3, i32 1)
%10 = call i32 @inb(i32 888)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @inb(i32 889)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 @inb(i32 890)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 @ioperm(i32 888, i32 3, i32 0)
%17 = call i32 @ioperm(i32 889, i32 3, i32 0)
%18 = call i32 @ioperm(i32 890, i32 3, i32 0)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %20
20: ; preds = %6, %4
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"DATA: %4d\0A\00"
@.str.2 = [13 x i8] c"STATUS: %4d\0A\00"
@.str.3 = [14 x i8] c"CONTROL: %4d\0A\00"
@str = [32 x i8] c"Program musi byt spusten rootem\00"
define i32 @main() {
%1 = tail call i64 @setuid(i32 0)
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %19
5: ; preds = %0
%6 = tail call i32 @ioperm(i32 888, i32 3, i32 1)
%7 = tail call i32 @ioperm(i32 889, i32 3, i32 1)
%8 = tail call i32 @ioperm(i32 890, i32 3, i32 1)
%9 = tail call i32 @inb(i32 888)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @inb(i32 889)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = tail call i32 @inb(i32 890)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 @ioperm(i32 888, i32 3, i32 0)
%16 = tail call i32 @ioperm(i32 889, i32 3, i32 0)
%17 = tail call i32 @ioperm(i32 890, i32 3, i32 0)
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %5, %3
ret i32 0
}