#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 O_CREAT;
int O_EXCL;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *, int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
void routine(char *argv0, char *filename, char byte, unsigned int size) {
  unsigned int wrote = 0;
  int fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644);
  if (fd < 0)
    usage(argv0, strerror(errno));
  while (wrote < size) {
    if (write(fd, &byte, 1) < 0)
      usage(argv0, strerror(errno));
    ++wrote;
  }
  close(fd);
}


x86 assembly (clang, -O0):
<routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e75(%rip),%rax
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11c6 <routine+0x76>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <usage@plt>
jmp    11cb <routine+0x7b>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1221 <routine+0xd1>
mov    -0x20(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1213 <routine+0xc3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1050 <usage@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cb <routine+0x7b>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<routine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %rsi,%rax
mov    %rdi,%r14
mov    0x2e55(%rip),%rcx
mov    0x2e86(%rip),%rsi
mov    (%rsi),%esi
or     (%rcx),%esi
mov    %dl,0xf(%rsp)
mov    0x2e57(%rip),%rcx
or     (%rcx),%esi
mov    %rax,%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     119c <routine+0x4c>
test   %ebx,%ebx
jne    11b8 <routine+0x68>
jmp    11fe <routine+0xae>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <usage@plt>
test   %ebx,%ebx
je     11fe <routine+0xae>
lea    0xf(%rsp),%r15
mov    0x2e0c(%rip),%r12
jmp    11d5 <routine+0x85>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     11fe <routine+0xae>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    11d0 <routine+0x80>
mov    (%r12),%edi
call   1070 <strerror@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <usage@plt>
jmp    11d0 <routine+0x80>
mov    %ebp,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i32 0
define void @routine(i8* %0, i8* %1, i8 signext %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%11 = load i8*, i8** %6
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @O_EXCL
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %11, i32 %16, i32 420)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @usage(i8* %21, i32 %23)
br label %25
25: ; preds = %20, %4
br label %26
26: ; preds = %39, %25
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = icmp ult i32 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i32, i32* %10
%32 = call i64 @write(i32 %31, i8* %7, i32 1)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = load i32, i32* @errno
%37 = call i32 @strerror(i32 %36)
%38 = call i32 @usage(i8* %35, i32 %37)
br label %39
39: ; preds = %34, %30
%40 = load i32, i32* %9
%41 = add i32 %40, 1
store i32 %41, i32* %9
br label %26
42: ; preds = %26
%43 = load i32, i32* %10
%44 = call i32 @close(i32 %43)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i32 0
define void @routine(i8* %0, i8* nocapture %1, i8 signext %2, i32 %3) {
%5 = alloca i8
store i8 %2, i8* %5
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_EXCL
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %1, i32 %10, i32 420)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 @usage(i8* %0, i32 %15)
br label %17
17: ; preds = %13, %4
%18 = icmp eq i32 %3, 0
br i1 %18, label %30, label %19
19: ; preds = %17, %27
%20 = phi i32 [ %28, %27 ], [ 0, %17 ]
%21 = call i64 @write(i32 %11, i8* %5, i32 1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @errno
%25 = tail call i32 @strerror(i32 %24)
%26 = tail call i32 @usage(i8* %0, i32 %25)
br label %27
27: ; preds = %23, %19
%28 = add nuw i32 %20, 1
%29 = icmp eq i32 %28, %3
br i1 %29, label %30, label %19
30: ; preds = %27, %17
%31 = tail call i32 @close(i32 %11)
ret void
}