#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 my_state {
  int dummy;
};

/* Variables and functions */
int do_out(struct my_state *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int foo(struct my_state *s, int param) {
  if (param <= 0)
    return -1;
  while (param) {
    int res = do_out(s, param--);
    printf("Result=%d\n", res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1145 <foo+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <foo+0x66>
jmp    114a <foo+0x2a>
cmpl   $0x0,-0x14(%rbp)
je     117f <foo+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    %esi,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
call   1040 <do_out@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    114a <foo+0x2a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
test   %esi,%esi
jle    1161 <foo+0x41>
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xecb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <do_out@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0xffffffff,%ebx
jne    1140 <foo+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.my_state = type { i32 }
@.str = [11 x i8] c"Result=%d\0A\00"
define i32 @foo(%struct.my_state* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.my_state*
%5 = alloca i32
%6 = alloca i32
store %struct.my_state* %0, %struct.my_state** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %22
10: ; preds = %2
br label %11
11: ; preds = %14, %10
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load %struct.my_state*, %struct.my_state** %4
%16 = load i32, i32* %5
%17 = add nsw i32 %16, -1
store i32 %17, i32* %5
%18 = call i32 @do_out(%struct.my_state* %15, i32 %16)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %11
21: ; preds = %11
store i32 0, i32* %3
br label %22
22: ; preds = %21, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.my_state = type { i32 }
@.str = [11 x i8] c"Result=%d\0A\00"
define i32 @foo(%struct.my_state* %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %10, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %6, %4 ], [ %1, %2 ]
%6 = add nsw i32 %5, -1
%7 = tail call i32 @do_out(%struct.my_state* %0, i32 %5)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %4
10: ; preds = %4, %2
%11 = phi i32 [ -1, %2 ], [ 0, %4 ]
ret i32 %11
}