#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*/ dieNeg(int, char *);
int /*<<< orphan*/ printf(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, char);
int write(int, char *, int);
void writeLockRequest(int fd, int lockbits) {
  int ret;
  char buf;
  buf = lockbits;
  ret = write(fd, &buf, 1);
  if (ret < 0) {
    char msg[200];
    sprintf(msg, "Write '\\%03o' failed", buf);
    dieNeg(ret, msg);
  }
  printf("Write '\\%03o' returned %d\n", buf, ret);
}


x86 assembly (clang, -O0):
<writeLockRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0xd(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119b <writeLockRequest+0x5b>
lea    -0xe0(%rbp),%rdi
lea    0xe7d(%rip),%rsi
movsbl -0xd(%rbp),%edx
call   1060 <sprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0xe0(%rbp),%rsi
call   1040 <dieNeg@plt>
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%edx
lea    0xe6d(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeLockRequest>:
push   %rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %esi,%ebp
mov    %bpl,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebx
movsbl %bpl,%ebp
test   %eax,%eax
jns    118b <writeLockRequest+0x4b>
lea    0xe8e(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <dieNeg@plt>
lea    0xe83(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <printf@plt>
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Write '\\%03o' failed\00"
@.str.1 = [27 x i8] c"Write '\\%03o' returned %d\0A\00"
define void @writeLockRequest(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca [200 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = trunc i32 %8 to i8
store i8 %9, i8* %6
%10 = load i32, i32* %3
%11 = call i32 @write(i32 %10, i8* %6, i32 1)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%16 = load i8, i8* %6
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 signext %16)
%18 = load i32, i32* %5
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%20 = call i32 @dieNeg(i32 %18, i8* %19)
br label %21
21: ; preds = %14, %2
%22 = load i8, i8* %6
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8 signext %22, i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Write '\\%03o' failed\00"
@.str.1 = [27 x i8] c"Write '\\%03o' returned %d\0A\00"
define void @writeLockRequest(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca [200 x i8]
%5 = trunc i32 %1 to i8
store i8 %5, i8* %3
%6 = call i32 @write(i32 %0, i8* %3, i32 1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%11 = call i32 @dieNeg(i32 %6, i8* %9)
br label %12
12: ; preds = %8, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8 signext %5, i32 %6)
ret void
}