#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*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int do_pwr_dn(int fd, int cycleCnt) {
  char buf[200];
  sprintf(buf, "ok to power me down!\nCount = %i\n", cycleCnt);
  if (write(fd, buf, strlen(buf)) < strlen(buf)) {
    perror("write error");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_pwr_dn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe9e(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xf4(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xe8(%rbp),%rax
cmp    %rcx,%rax
jge    11dd <do_pwr_dn+0x9d>
lea    0xe55(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <do_pwr_dn+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pwr_dn>:
push   %rbp
push   %rbx
sub    $0xc8,%rsp
mov    %esi,%edx
mov    %edi,%ebp
lea    0xeac(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbp
jl     1193 <do_pwr_dn+0x53>
add    $0xc8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1189 <do_pwr_dn+0x49>

LLVM IR (-O0):
@.str = [33 x i8] c"ok to power me down!\0ACount = %i\0A\00"
@.str.1 = [12 x i8] c"write error\00"
define i32 @do_pwr_dn(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [200 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %5
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
%14 = call i64 @write(i32 %10, i8* %11, i64 %13)
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
%17 = icmp slt i64 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
20: ; preds = %2
store i32 0, i32* %3
br label %21
21: ; preds = %20, %18
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [33 x i8] c"ok to power me down!\0ACount = %i\0A\00"
@.str.1 = [12 x i8] c"write error\00"
define i32 @do_pwr_dn(i32 %0, i32 %1) {
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i64 @strlen(i8* %4)
%7 = call i64 @write(i32 %0, i8* %4, i64 %6)
%8 = call i64 @strlen(i8* %4)
%9 = icmp slt i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ -1, %10 ], [ 0, %2 ]
ret i32 %13
}