#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 */
struct ser_device {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ser_putchar(struct ser_device *, char);
int ser_write(struct ser_device *dev, size_t n, void *p) {
  char *s = p;
  while (n) {
    if (ser_putchar(dev, *s) != (0))
      return (-5);
    s++;
    n--;
  }
  return (0);
}


x86 assembly (clang, -O0):
<ser_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1179 <ser_write+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
call   1030 <ser_putchar@plt>
cmp    $0x0,%eax
je     115c <ser_write+0x4c>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1180 <ser_write+0x70>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <ser_write+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ser_write>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     114a <ser_write+0x3a>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
call   1030 <ser_putchar@plt>
test   %eax,%eax
jne    114e <ser_write+0x3e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <ser_write+0x20>
xor    %eax,%eax
jmp    1153 <ser_write+0x43>
mov    $0xfffffffb,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ser_device = type { i32 }
define i32 @ser_write(%struct.ser_device* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ser_device*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store %struct.ser_device* %0, %struct.ser_device** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
store i8* %9, i8** %8
br label %10
10: ; preds = %20, %3
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load %struct.ser_device*, %struct.ser_device** %5
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = call i32 @ser_putchar(%struct.ser_device* %14, i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -5, i32* %4
br label %26
20: ; preds = %13
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %8
%23 = load i64, i64* %6
%24 = add i64 %23, -1
store i64 %24, i64* %6
br label %10
25: ; preds = %10
store i32 0, i32* %4
br label %26
26: ; preds = %25, %19
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.ser_device = type { i32 }
define i32 @ser_write(%struct.ser_device* %0, i64 %1, i8* nocapture %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %15, label %5
5: ; preds = %3, %11
%6 = phi i8* [ %12, %11 ], [ %2, %3 ]
%7 = phi i64 [ %13, %11 ], [ %1, %3 ]
%8 = load i8, i8* %6
%9 = tail call i32 @ser_putchar(%struct.ser_device* %0, i8 signext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = add i64 %7, -1
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %11, %3
%16 = phi i32 [ 0, %3 ], [ 0, %11 ], [ -5, %5 ]
ret i32 %16
}