#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 EBADF;
int /*<<< orphan*/ __NR_write;
int /*<<< orphan*/ assert(int);
int errno;
int syscall(int /*<<< orphan*/, int, char *, int);
int main() {
  int a, b;
  syscall(__NR_write, 1, "foo\n", 4);
  a = syscall(__NR_write, 23, "bar\n", 4);
  b = errno;
  assert(a == -1);
  assert(b == EBADF);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
lea    0xebc(%rip),%rdx
mov    $0x4,%ecx
call   1040 <syscall@plt>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    $0x17,%esi
lea    0xea2(%rip),%rdx
mov    $0x4,%ecx
call   1040 <syscall@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ec0(%rip),%rbx
mov    (%rbx),%edi
lea    0xecf(%rip),%rdx
mov    $0x1,%esi
mov    $0x4,%ecx
call   1040 <syscall@plt>
mov    (%rbx),%edi
lea    0xebc(%rip),%rdx
mov    $0x17,%esi
mov    $0x4,%ecx
call   1040 <syscall@plt>
mov    0x2e79(%rip),%rcx
mov    (%rcx),%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1030 <assert@plt>
mov    0x2e5a(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%ebx
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__NR_write = global i32 0
@.str = [5 x i8] c"foo\0A\00"
@.str.1 = [5 x i8] c"bar\0A\00"
@errno = global i32 0
@EBADF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @__NR_write
%5 = call i32 @syscall(i32 %4, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%6 = load i32, i32* @__NR_write
%7 = call i32 @syscall(i32 %6, i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
store i32 %7, i32* %2
%8 = load i32, i32* @errno
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %3
%14 = load i32, i32* @EBADF
%15 = icmp eq i32 %13, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
ret i32 0
}

LLVM IR (-O2):
@__NR_write = global i32 0
@.str = [5 x i8] c"foo\0A\00"
@.str.1 = [5 x i8] c"bar\0A\00"
@errno = global i32 0
@EBADF = global i32 0
define i32 @main() {
%1 = load i32, i32* @__NR_write
%2 = tail call i32 @syscall(i32 %1, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%3 = load i32, i32* @__NR_write
%4 = tail call i32 @syscall(i32 %3, i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%5 = load i32, i32* @errno
%6 = icmp eq i32 %4, -1
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i32, i32* @EBADF
%10 = icmp eq i32 %5, %9
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
ret i32 0
}