#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 errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int setuid(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int main() {
  int valor;
  valor = setuid(0);
  if (valor == -1) {
    perror("ERROR SETUID");
    printf("Número del error es: %i\n", errno);
  }
  printf("***Imprimiendo mensajes de error disponibles en el sistema ***\n");
  int i = 1;
  while (strcmp(strerror(i), strerror(i + 1)) != 0) {
    printf("ERROR %d: %s\n", i, strerror(i));
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <setuid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1196 <main+0x46>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1208 <main+0xb8>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ab <main+0x5b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <setuid@plt>
cmp    $0xffffffff,%eax
je     120f <main+0xaf>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1080 <strerror@plt>
mov    %rax,%rbp
mov    $0x2,%edi
call   1080 <strerror@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1202 <main+0xa2>
lea    0xe71(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15d
mov    %ebx,%edi
call   1080 <strerror@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
call   1080 <strerror@plt>
mov    %rax,%rbp
add    $0x2,%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
mov    %r15d,%ebx
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdea(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xde2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1177 <main+0x17>

LLVM IR (-O0):
@.str = [13 x i8] c"ERROR SETUID\00"
@.str.1 = [26 x i8] c"N\C3\BAmero del error es: %i\0A\00"
@errno = global i32 0
@.str.2 = [64 x i8] c"***Imprimiendo mensajes de error disponibles en el sistema ***\0A\00"
@.str.3 = [14 x i8] c"ERROR %d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @setuid(i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %13
13: ; preds = %21, %11
%14 = load i32, i32* %3
%15 = call i8* @strerror(i32 %14)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
%18 = call i8* @strerror(i32 %17)
%19 = call i64 @strcmp(i8* %15, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %13
%22 = load i32, i32* %3
%23 = load i32, i32* %3
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %22, i8* %24)
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %13
28: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"ERROR SETUID\00"
@.str.1 = [26 x i8] c"N\C3\BAmero del error es: %i\0A\00"
@errno = global i32 0
@.str.3 = [14 x i8] c"ERROR %d: %s\0A\00"
@str = [63 x i8] c"***Imprimiendo mensajes de error disponibles en el sistema ***\00"
define i32 @main() {
%1 = tail call i32 @setuid(i32 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @errno
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %3, %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%9 = tail call i8* @strerror(i32 1)
%10 = tail call i8* @strerror(i32 2)
%11 = tail call i64 @strcmp(i8* %9, i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %7, %13
%14 = phi i32 [ %19, %13 ], [ 2, %7 ]
%15 = phi i32 [ %14, %13 ], [ 1, %7 ]
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %15, i8* %16)
%18 = tail call i8* @strerror(i32 %14)
%19 = add nuw nsw i32 %14, 1
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i64 @strcmp(i8* %18, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %13
23: ; preds = %13, %7
ret i32 0
}