#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*/ LC_MESSAGES;
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
char *strerror(long);
long strtol(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *cp;
  char *errstr;
  long errnum;
  (void)setlocale(LC_MESSAGES, "");
  if (argc != 2)
    usage();
  errno = 0;
  errnum = strtol(argv[1], &cp, 0);
  if (errno != 0)
    err(1, NULL);
  if ((errstr = strerror(errnum)) == NULL)
    err(1, NULL);
  printf("%s\n", errstr);
  exit(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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <setlocale@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ac <main+0x3c>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2e2d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e08(%rip),%rax
cmpq   $0x0,(%rax)
je     11f0 <main+0x80>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x28(%rbp),%rdi
call   1090 <strerror@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1215 <main+0xa5>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x20(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1060 <setlocale@plt>
cmp    $0x2,%ebp
je     1199 <main+0x29>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2e40(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
cmpq   $0x0,0x0(%rbp)
je     11cc <main+0x5c>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <err@plt>
mov    %rbx,%rdi
call   1090 <strerror@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e8 <main+0x78>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <err@plt>
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@LC_MESSAGES = global i32 0
@.str = [1 x i8] zeroinitializer
@errno = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @LC_MESSAGES
%10 = call i32 @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (...) @usage()
br label %15
15: ; preds = %13, %2
store i64 0, i64* @errno
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strtol(i8* %18, i8** %6, i32 0)
store i64 %19, i64* %8
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @err(i32 1, i32* null)
br label %24
24: ; preds = %22, %15
%25 = load i64, i64* %8
%26 = call i8* @strerror(i64 %25)
store i8* %26, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @err(i32 1, i32* null)
br label %30
30: ; preds = %28, %24
%31 = load i8*, i8** %7
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@LC_MESSAGES = global i32 0
@.str = [1 x i8] zeroinitializer
@errno = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @LC_MESSAGES
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 (...) @usage()
br label %10
10: ; preds = %8, %2
store i64 0, i64* @errno
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i8** %3, i32 0)
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = tail call i32 @err(i32 1, i32* null)
br label %18
18: ; preds = %16, %10
%19 = tail call i8* @strerror(i64 %13)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @err(i32 1, i32* null)
br label %23
23: ; preds = %21, %18
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%25 = tail call i32 @exit(i32 0)
unreachable
}