#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*/ EINVAL;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fputs("usage: errno <error number>\n", stderr);
    return EXIT_FAILURE;
  }
  char *endptr;
  char *nptr = argv[1];
  errno = strtol(nptr, &endptr, 10);
  if (!(nptr[0] != '\0' && endptr[0] == '\0')) {
    errno = EINVAL;
    perror(NULL);
    return EXIT_FAILURE;
  }
  perror(nptr);
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     1176 <main+0x46>
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    0x2e3b(%rip),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bf <main+0x8f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11eb <main+0xbb>
mov    0x2e02(%rip),%rax
mov    (%rax),%ecx
mov    0x2e09(%rip),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <perror@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <main+0xd0>
mov    -0x20(%rbp),%rdi
call   1050 <perror@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
je     115e <main+0x2e>
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsi),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e5d(%rip),%rcx
mov    %eax,(%rcx)
cmpb   $0x0,(%rbx)
je     119d <main+0x6d>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    119d <main+0x6d>
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    0x2e25(%rip),%rax
jmp    1156 <main+0x26>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
xor    %edi,%edi
call   1050 <perror@plt>
jmp    114f <main+0x1f>

LLVM IR (-O0):
@.str = [29 x i8] c"usage: errno <error number>\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@EINVAL = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %39
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = call i32 @strtol(i8* %18, i8** %6, i32 10)
store i32 %19, i32* @errno
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %14
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25, %14
%32 = load i32, i32* @EINVAL
store i32 %32, i32* @errno
%33 = call i32 @perror(i8* null)
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %3
br label %39
35: ; preds = %25
%36 = load i8*, i8** %7
%37 = call i32 @perror(i8* %36)
%38 = load i32, i32* @EXIT_SUCCESS
store i32 %38, i32* %3
br label %39
39: ; preds = %35, %31, %10
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [29 x i8] c"usage: errno <error number>\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@EINVAL = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @EXIT_FAILURE
br label %28
9: ; preds = %2
%10 = bitcast i8** %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strtol(i8* %12, i8** %3, i32 10)
store i32 %13, i32* @errno
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16, %9
%21 = load i32, i32* @EINVAL
store i32 %21, i32* @errno
%22 = tail call i32 @perror(i8* null)
br label %25
23: ; preds = %16
%24 = tail call i32 @perror(i8* %12)
br label %25
25: ; preds = %23, %20
%26 = phi i32* [ @EXIT_SUCCESS, %23 ], [ @EXIT_FAILURE, %20 ]
%27 = load i32, i32* %26
br label %28
28: ; preds = %25, %5
%29 = phi i32 [ %8, %5 ], [ %27, %25 ]
ret i32 %29
}