#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*/ printf(char *, char const *, ...);
char *strerror(int);
void result(const char *msg, int err) {
  const char *errmsg = strerror(errno);
  if (err)
    printf("%-30s: FAILED (%d, %s)\n", msg, errno, errmsg);
  else
    printf("%-30s: OK\n", msg);
}


x86 assembly (clang, -O0):
<result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     116f <result+0x4f>
mov    -0x8(%rbp),%rsi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1181 <result+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<result>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2eb0(%rip),%r14
mov    (%r14),%edi
call   1040 <strerror@plt>
test   %ebp,%ebp
je     1157 <result+0x37>
mov    (%r14),%edx
lea    0xeba(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [24 x i8] c"%-30s: FAILED (%d, %s)\0A\00"
@.str.1 = [11 x i8] c"%-30s: OK\0A\00"
define void @result(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* @errno
%7 = call i8* @strerror(i32 %6)
store i8* %7, i8** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = load i8*, i8** %5
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12, i8* %13)
br label %18
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %10
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [24 x i8] c"%-30s: FAILED (%d, %s)\0A\00"
@.str.1 = [11 x i8] c"%-30s: OK\0A\00"
define void @result(i8* %0, i32 %1) {
%3 = load i32, i32* @errno
%4 = tail call i8* @strerror(i32 %3)
%5 = icmp eq i32 %1, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %7, i8* %4)
br label %11
9: ; preds = %2
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %6
ret void
}