#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 atoi(char *);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char buf[10];
  if (argc != 2) {
    fprintf(stderr, "Usage: perror errno\n");
  }
  errno = argc > 1 ? atoi(argv[1]) : 0;
  snprintf(buf, 10, "errno %d", errno);
  perror(buf);
  return errno;
}


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     1175 <main+0x35>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1194 <main+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    119e <main+0x5e>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    119e <main+0x5e>
mov    -0x20(%rbp),%ecx
mov    0x2e30(%rip),%rax
mov    %ecx,(%rax)
lea    -0x1a(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%ecx
mov    $0xa,%esi
lea    0xe52(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x1a(%rbp),%rdi
call   1050 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     116c <main+0x2c>
mov    %edi,%ebp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ecx,%ecx
cmp    $0x2,%ebp
jl     1177 <main+0x37>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    0x2e5a(%rip),%rbp
mov    %ecx,0x0(%rbp)
lea    0xe8d(%rip),%rdx
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    0x0(%rbp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: perror errno\0A\00"
@errno = global i32 0
@.str.1 = [9 x i8] c"errno %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
br label %21
20: ; preds = %12
br label %21
21: ; preds = %20, %15
%22 = phi i32 [ %19, %15 ], [ 0, %20 ]
store i32 %22, i32* @errno
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* @errno
%25 = call i32 @snprintf(i8* %23, i32 10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%27 = call i32 @perror(i8* %26)
%28 = load i32, i32* @errno
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: perror errno\0A\00"
@errno = global i32 0
@.str.1 = [9 x i8] c"errno %d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2, %6
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %14
14: ; preds = %6, %10
%15 = phi i32 [ %13, %10 ], [ 0, %6 ]
store i32 %15, i32* @errno
%16 = call i32 @snprintf(i8* %4, i32 10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @perror(i8* %4)
%18 = load i32, i32* @errno
ret i32 %18
}